I'm customizing a geoprocessing tool that runs an arcpy.un.Trace.
I can successfully run the GP tool in ArcGIS Pro, but when I publish it to ArcGIS Enterprise, I receive the following message:
"Parameters are not valid. ERROR 000840: The value is not a String. Failed to execute (Trace)."
g_ESRI_variable_4 = 'https://myportal/server/rest/services/Water/Water/FeatureServer/8'
arcpy.un.Trace(
in_utility_network=g_ESRI_variable_4,
trace_type="ISOLATION",
starting_points=temp_starting,
domain_network="Water",
tier="Distribuição",
out_json_file=trace_json
)
Does someone once made an GP tool that runs a Trace and worked?
I'm not confident that using a service URL directly in the in_utility_network works for this call. Have you tried to use the arcpy.management.MakeFeatureLayer to create a temporary layer object from the URL, and then pass it to the in_utility_network parameter?
I cannot create a temporary layer using a specific sublayer such as “FeatureServer/8” (my network layer).
Temporary layers created from individual sublayers cannot be used as in_utility_network, since they are not recognized as a Utility Network.
Makes sense. Two more questions (I'm trying to reproduce your scenario on my environment):
1 - Assuming your UN service is secured, are you setting the active portal and signing in before executing the Trace?
2 - What's the content of the temp_starting variable?
Thank you very much, Roberto.
1 - Assuming your UN service is secured, are you setting the active portal and signing in before executing the Trace?
A: That’s a good question. I'm currently not signing in because all the services are in registered datastores, so I thought I didn’t need to log in within my GP tool. However, I will set the login and test it again.
2 - What's the content of the temp_starting variable?
A: I’ll paste below the relevant part of my code.
#start by creating my startingpoint in scratch
temp_starting = arcpy.management.CreateFeatureclass(
out_path=scratch_gdb,
out_name="UN_TEMP_STARTING_POINT",
geometry_type="POINT",
spatial_reference=arcpy.SpatialReference(31983),
has_z="DISABLED",
has_m="DISABLED"
).getOutput(0)
fields = [
("LAYERNAME", "TEXT", 255, None, None, None),
("FEATUREGLOBALID", "GUID", None, None, None, None),
("TERMINALID", "LONG", None, 10, 0, None),
("PERCENTALONG", "DOUBLE", None, 38, 8, None),
]
for name, ftype, length, precision, scale, domain in fields:
arcpy.management.AddField(
in_table=temp_starting,
field_name=name,
field_type=ftype,
field_precision=precision if precision else None,
field_scale=scale if scale else None,
field_length=length if length else None,
field_alias=name,
field_is_nullable="NULLABLE",
field_is_required="NON_REQUIRED",
field_domain=domain if domain else ""
)
# search global id parameter (the user must input)
where_clause = f"GLOBALID = '{globalid}'"
layer_name = "pipe_selection"
arcpy.env.preserveGlobalIds = True
filtro_inicial = arcpy.management.MakeFeatureLayer(pipe_input, layer_name, where_clause)
arcpy.AddMessage(f"Feições copiadas para: {filtro_inicial}")
with arcpy.da.SearchCursor(filtro_inicial, ["GLOBALID", "SHAPE@"]) as s_cursor, \
arcpy.da.InsertCursor(temp_starting,
["SHAPE@", "LAYERNAME", "FEATUREGLOBALID", "TERMINALID", "PERCENTALONG"]) as i_cursor:
for globalid, shape in s_cursor:
centroid = shape.positionAlongLine(0.5, use_percentage=True)
percent_along = 0.5
i_cursor.insertRow((centroid, "Tubulação", globalid, "-1", percent_along))
arcpy.AddMessage(f"Trace location criada: {temp_starting}")
So, when the user enters the pipe’s GlobalID, this part of the code automatically calculates all the starting_point parameters. Then I use this temp_starting feature class as the starting_point input in the Trace tool.
I’m no longer receiving any errors related to this parameter (I was struggling with that before, haha).