I am using ArcMap 10.5. I need to have a field where a unique ID is generated every time I add a point/polygon/feature. How would I go about doing this? I've tried some Python and VBA scripts seen on Geonet however they did not seem to work. Also, If I am able to get this working in ArcMap will that same functionality transfer over to the Collector App if I publish the layer to collect points?
Hi Joel,
The attribute assistant can achieve this. Take a look at the Sequences and Id.
Is seems like your backend GDB is an enterprise and not file GDB? Correct?
Beyond saying you tried some stuff and it didn't work, it is helpful to reference what you have tried and what didn't work specifically. For example, I tried (insert link) and I get the following error message.
Hi Joel,
I'd recommend a GLOBALID field, which is the ideal primary key for related records. If you publish this dataset as an Esri-hosted Feature Service, the GlobalID values will be generated each time you create a new feature in Collector. You can Add Global IDs in ArcCatalog or with geoprocessing.
Micah
It is a database question. I think it is better if you move this question to https://community.esri.com/groups/geodatabase?sr=search&searchId=34a288dd-548f-47db-99f3-f218563cdd6... .
Joel,
If you are using a enterprise database you can use Add Incrementing ID Field—Help | ArcGIS Desktop .
~Shan
Moved to https://community.esri.com/community/gis/applications/collector-for-arcgis?sr=search&searchId=e36ff7.... Functionality that exists within ArcMap is not necessarily implemented in other software. They would best able to answer your question.
I had this issue and went the following route:
If the field that is the ID is a number field, create a view for creating the next ID in sequence in SQL Server such as:
SELECT MAX(FieldName) + 1 AS NEXT_ID
FROM owner.TABLENAME
Then, in Model Builder, I created a model to assign the ID.
Get Field Value: Using your view that you created: Field is NEXT_ID, Data Type is Long
Make a Feature Layer of the feature class you are trying to update, then Select By Attribute as "FieldName IS NULL", then calculate "FieldName" with the "Value" from the next available ID
Calculate Field (Python 9.3):
Expression:
autoIncrement()
Code Block:
rec=0
def autoIncrement():
global rec
pStart = %Value%
pInterval = 1
if (rec == 0):
rec = pStart
else:
rec += pInterval
return rec
From here, you can import the Model Builder model into a Python script as:
arcpy.ImportToolbox("C:\Path\To\Your\Toolbox\AutoID.tbx","test")
arcpy.ModelName_test()
Make sure you add _test() to the end of your model name and "test" at the end of your toolbox.
Thanks for this Brian. I will give it a try.
Were you able to get this to run in Python?
I noticed get Field Value is intended for use in ModelBuilder and not in Python scripting