Generate an auto populating unique ID field in ArcMap

19152
9
07-07-2017 08:55 AM
JoelGuerra1
New Contributor

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?

0 Kudos
9 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Joel,

The attribute assistant can achieve this.  Take a look at the Sequences and Id.

JoshuaBixby
MVP Esteemed Contributor

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.

0 Kudos
MicahBabinski
Occasional Contributor III

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

0 Kudos
AbdullahAnter
Occasional Contributor III

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...‌ .

0 Kudos
shan_sarkar
Occasional Contributor III

Joel,

If you are using a enterprise database you can use Add Incrementing ID Field—Help | ArcGIS Desktop .

~Shan


~Shan
0 Kudos
DanPatterson_Retired
MVP Emeritus

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.

Brian_McLeer
Occasional Contributor II

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. 

Brian
0 Kudos
JoelGuerra1
New Contributor

Thanks for this Brian. I will give it a try.

0 Kudos
PatrL
by
New Contributor

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

0 Kudos