Hi Everyone,
I was wondering if it's possible to create a sequential ID field with a sorted field that is not Object ID, referencing a web layer in My Content of ArcGIS Online (as opposed to a locally-stored layer). I've tried to create a Python script to feed into the Python shell of ArcGIS Pro, referencing a web-hosted layer in my active map. The script is a derivative of the following:
How To: Sort and create a sequentially ordered ID field in an attribute table in ArcGIS Pro
I'm trying to sort the field Asset_ID_OLD and use this sequence to populate Asset_ID_ with sequential ID numbers, beginning with FH1. This is what my script looks like:
import arcpy
sortFeat = r'Hydrants'
sortField = 'Asset_ID_OLD'
idField = 'Asset_ID_'
Count = 1
def Renum():
global Count
Interval = 1
if Count == 1:
New = "FH" + str(Count)
Count += Interval
return New
else:
New = "FH" + str(Count)
Count += Interval
return New
rows = arcpy.UpdateCursor(sortFeat, "", "", "", sortField + " A")
for row in rows:
row.setValue(idField, Renum())
rows.updateRow(row)
del row, rows
When I enter this code into the Python console, I get this message:
Traceback (most recent call last):
File "<string>", line 19, in <module>
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\__init__.py", line 1213, in UpdateCursor
return gp.updateCursor(dataset, where_clause, spatial_reference, fields, sort_fields)
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 368, in updateCursor
self._gp.UpdateCursor(*gp_fixargs(args, True)))
RuntimeError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.
What am I doing wrong? Is it even possible to do this using a web-hosted layer? Am I referencing the layer incorrectly? Or is this another problem?
Also, I'm not really sure what the + " A" part means in the original script...