Sunday 13 January 2019

arcpy - Auto-generated field in ArcSDE for end user


The objective: Create a process where a coworker can open an .MXD, start editing, add a feature to represent a complaint, then add records in a related table to represent an inspection. Along the way, I want the coworker to be able to use a unique number that is auto-generated as part of a larger docket number.


I am using global IDs in a relationship class to relate the Complaint feature with the Inspections table. I am doing this so that I can easily hide the global ID field in the .MXD my coworker is using so there is no risk that they will accidentally break the relationship by changing the value.


The problem: The complaint feature needs to have another unique field with an incremental value that can be used to build a docket number. Object ID will not work because that can change, and because in an SDE environment the Object ID increases by 400 every editing session (before long the number would be way too large). So I basically need a project ID that will start at 0 or 1 and go up by one for every record that is added. I could then make this field read only in my coworkers .MXD so they can only view but not change it.


The kicker here is, I really want this process to be done automatically as soon as my coworker creates a new record during an editing session. I realize this is probably impossible, so is there a way to do it through a script that runs every night so the number is available for my coworker the next day? The important thing is that this number is always unique and is not repeated if, say, an earlier record is deleted (autoincrement field calculate would have this problem).


We are working with ArcGIS 10.2.2 in an SDE environment on a SQL server (I think Microsoft 2008 but not sure).



Answer




Esri's Attribute Assistant has a tool called Generate ID which will automatically generate a new ID whenever a new feature is created.


These IDs can be created per feature class to generate different IDs for different feature classes, and can be created based on a specific template if required.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...