Many workflows require that a unique identifier be generated when a feature or record is created so it can be referenced and tracked in other workflows. The Generate IDs tool can be used to configure custom unique identifiers that will be applied to features at a regularly scheduled interval of your choosing. Note that the tool only generates the configuration; an additional script (provided) must be run to actually update the features with incrementing identifier values.
Configuring and executing this script requires the ArcGIS API for Python (Installed with ArcGIS Pro).
To configure the generation of IDs for features, complete the following steps:
- Download and extract the ServiceFunctions toolbox. The tools in this toolbox create and update a configuration file that can then serve as input for a scheduled script.
- Open the toolbox in ArcGIS Pro 2.x and, if you've never used the toolbox before, run the Define Connection Settings tool to establish a connection between the toolbox and the ArcGIS Enterprise portal or ArcGIS Online organization containing the layers for which you want to generate IDs.
- Open the Generate IDs tool.
- If the tool has not been run previously, start by specifying at least one identifier sequence in the General Identifier Settings section of the tool by providing the following values:
- Sequence Name—Assign a name to the sequence. This value will appear in the drop-down menu for selecting the sequence to assign to each layer.
- Pattern—The pattern to use for the sequence. This can be a combination of letters, number, and symbols. Mark the location for the incrementing value with a pair of curly braces {}. Python formatting will be applied to the pattern text, so string formatting syntax such as {0:03d} will pad the incrementing number section with zeros to a length of 3. For example, the pattern seq-{0:05d} would result in identifier values such as 'seq-0001', 'seq-002', 'seq-0010', etc.
- Next Value—When initially creating the sequence, this should be the first value you'd like to use in the identifiers. After this point, this value will show the value to be used for the next identifier generated.
- Interval—The interval by which the identifier values should increase between features. For example, an initial Next Value of 1 and an Interval of 10 would create identifiers with the incrementing values of 1, 11, 21, etc.
- Choose the feature layer for which you'd like to generate identifiers by either choosing a layer from the active map, or by browsing to your hosted content and choosing a feature layer.
- If an identifier configuration already exists for the selected layer, a checkbox will appear that, when checked, will delete the existing identifier configuration for the selected layer. Alternatively, edit the identifier configuration and run the tool to overwrite the existing identifier configuration for the selected layer.
- Choose the sequence to use to generate the identifiers for each feature in the layer.
- Choose a text field to store the generated identifier.
- Run the tool to write out the identifier configuration for the layer and any changes to the identifier sequences. To run the updates on the layer, execute the servicefunctions.py script.
- To configure identifiers for another layer, re-run the tool with the settings for the next layer. Keep in mind that the General Identifier Settings are not specific to any one layer - they apply to all layers configured using this tool.
- To test the configuration, run the servicefunctions.py script that accompanies the toolbox. If errors occur, they will be written to a log file that will be created in the same directory as the script. The ServiceFunctions toolbox, servicefunctions.py script, and the servicefunctions.json file created by the toolbox must all remain in the same directory.
Set up Task Scheduler
Use Windows Task Scheduler to schedule the script to regularly scan the configured layers and generate IDs for new features.
This is only necessary if servicefunctions.py has not been previously scheduled. All the tools in this toolbox share a common configuration file and execution script so only one scheduled task is required to automate running all the associated processes.
- Open the Task Scheduler on the computer that is hosting the scripts.
- Click Action > Create Task and name your task.
- Click the Action tab and click New.
- Set Action to Start a Program.
- Browse to the location of your Python 3 installation (for example, <default directory>\C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe).
- In the Add arguments text box, type the name of the script (servicefunctions.py).
- In the Start in text box, type the path to the folder where your script is and click OK.
- Click the Trigger tab, click New, and set a schedule for your task.
- Click OK. When the trigger occurs, the scripts will begin scanning the configured layers and, for each one, processing (in order) configurations for generating identifiers, enriching reports, moderating reports, and sending emails.