This script has been moved to mature support.

Generate report IDs

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 ID script can be used to create unique identifiers with a schema of your choosing and apply those values to features at regularly scheduled intervals of your choosing.

Configuring and executing this script requires the following components:

  • Python 2.7 (Installed with ArcMap)

Make sure that your Python IDE is set to work against your Python 2.7 installation (for example, <default directory>\Python27\ArcGIS10.6\python.exe), and then skip ahead to the steps for configuring the script.

To set up the generate ID script, complete the following steps:

  1. Apply filters to the web map layers to restrict which features will be visible. These filters can be used to hide features that meet certain criteria, such as a specific attribute value, features older than a certain date, or features over a specified size.
  2. Unzip the folder to access the scripts, and use a Python IDE or text editor to open the calculateids.py file from the CalculateIds folder.
  3. At the server_type parameter, specify if the data is hosted in ArcGIS Online ('AGOL'), hosted in ArcGIS Enterprise ('PORTAL'), or a feature service published using ArcGIS Server ('SERVER').
  4. For services in ArcGIS Online or ArcGIS Enterprise, provide the URL to your organization and the credentials to an account that can edit the reporting layer in the orgURL, username, and password parameters. These values should be surrounded by quotation marks.
  5. List the services or feature classes to scan for new features in the data parameter by providing the following values for each data source:
    • 'data path': The URL to the REST endpoint of the service layer (ArcGIS Online and ArcGIS Enterprise) including the layer index number, or the path to the feature class that is the source of the service data (ArcGIS Server). Add an r to the front of the path, outside of the quotation marks, when specifying a file path to a feature class.
    • 'field name': Name of the field that will hold the calculated identifiers. This must reference a text field.
    • 'sequence name': Name of the identifier that will be used to generate ID values for this layer. This value should align with the first value in one of the rows in the accompanying ids.csv file, which will be discussed later.
    • 'pattern': The sequence of characters that will surround the incrementing value. The location of the incrementing value must be indicated with curly braces {}. For example, a sequence of 'seq-{}-abc' would generate identifiers such as seq-1-abc, seq-231-abc, and so on. You can also provide Python formatting instructions in the curly braces. For example, 'seq-{:04d}-abc' will generate identifiers where the incrementing portion is padded to 4 digits using zeros, such as 'seq-0001-abc' and 'seq-0231-abc'.
  6. The current values of the incrementing portions of the identifiers are stored in the ids.csv file found at the same location as the script. This file must exist at the same location as the calculateids.py script. If the name of the file is changed, the name will also need to be updated at the id_file_path parameter.
  7. Save and close the script.
  8. Open ids.csv. The first line of the file contains the headers for the following rows. The script ignores this first line, so don't delete it. The following lines should be customized for your own identifiers. Each line must have three values, in order:
    • sequence name: This is the name of the identifier. Each identifier must have a unique name. The type value specified for each service must match a value in this column. The other two columns ensure that the values of the identifiers increment correctly.
    • interval: This value must be a number. This is the number by which the identifiers will increment. For example, a value of 1 will generate a sequence of identifier values such as 1, 2, 3 while a value of 10 will generate values such as 1, 11, 21.
    • next value: This value must be a number. This is the number that will be used for the next identifier generated. To start with, set this value to the first number to use. As it completes, the script will update the value to keep track of where to start the next time it runs.
  9. Save your changes and test the script by double-clicking the calculateids.py file in Windows Explorer. The script will report any errors in a log file that will be created in the same directory as the script. Also verify that the expected changes occur in the service.

Set up Task Scheduler

Use Windows Task Scheduler to schedule the script to regularly scan the configured services and generate IDs as appropriate.

  1. Open the Task Scheduler on the desktop computer that is hosting the scripts.
  2. Click Action > Create Task and name your task.
  3. Click the Action tab and click New.
  4. Set Action to Start a Program.
  5. Browse to the location of your Python installation (for example, <default directory>\Python27\ArcGIS10.5\python.exe).
  6. In the Add arguments text box, type the name of the script (calculateids.py).
  7. In the Start in text box, type the path to the folder where your script is and click OK.
  8. Click the Trigger tab, click New, and set a schedule for your task.
  9. Click OK. When the trigger occurs, the scripts will begin scanning the specified layers.
Top