Hey everyone!
I'm new both to the community and to ArcGIS. I have been tasked with creating a python script that will complete a route analysis on a regular basis and so far that has been successful. One issue that I am having is that I am trying to sort of the field work_order_number, but I'm not quite sure how to do that. Here is the code that I have used to be able to create the route layer and add the stops with additional fields, but I have tried several ways to sort using the sort_field in AddLocations and was even trying to use arcpy.da.UpdateCursors.
routeLayer = arcpy.na.MakeRouteAnalysisLayer("https://www.arcgis.com/", f"Best Route {route_type_entry}", "Driving Time", "PRESERVE_FIRST", None, "LOCAL_TIME_AT_LOCATIONS", "ALONG_NETWORK", None, "DIRECTIONS", "LOCAL_TIME_AT_LOCATIONS")
#Adding fields to the route layer that were from the original table
#layer_object allows us to access the necessary parts of routeLayer to be able to add specific fields
layer_object = routeLayer.getOutput(0)
added_fields = [["Service_Address", "TEXT"],["Work_Order", "TEXT"],["Service_Date", "DATE"],["Route_Type", "TEXT"],["Description", "TEXT"],["Item_Size", "TEXT"], ["Work_Order_Status", "TEXT"]]
for i in range(len(added_fields)):
arcpy.na.AddFieldToAnalysisLayer(layer_object, "Stops", added_fields[i][0], added_fields[i][1])
## This process is importing the XY points into the route layer to be analyzed
## What is being passed in is the Network Analysis Layer, Stops table, the temporary view table, fields we want to include values for
arcpy.na.AddLocations(routeLayer, "Stops", viewTable, "CurbApproach # 3;Work_Order work_order_number #; Service_Address request_address #; Service_Date scheduled_pickup_date #; Route_Type route_type #; Description description #; Item_Size item_size #; Work_Order_Status work_order_status #;", "5000 Meters", None, None, "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "EXCLUDE", None)
Any help that I can get on this would be appreciated! Like I said, I'm brand new to the arcpy and ArcGIS world.