HOW TO

Automatically generate unique IDs with a prefix and prevent duplicates using attribute rules in ArcGIS Pro

First Published: October 1, 2026
Last Published: October 1, 2026

Summary

In ArcGIS Pro, an attribute rule can automatically populate a unique ID when creating a new feature, reducing the need for manual data entry. In some cases, the ID requires a fixed prefix and must be unique. Without an attribute rule, the ID in the attribute table below must be entered manually when creating a new feature, increasing the risk of duplicate IDs.

The ID field is not automatically populated, requiring manual entry of IDs

This article outlines a workflow for automatically populating a unique ID with a fixed prefix and a sequential number based on the next highest existing value in a separate field. The workflow also prevents duplicate IDs by returning an error when a duplicate value is entered and automatically updating the field with a valid value.

Cause



Procedure

  1. Open the ArcGIS Pro project.
  2. In the Contents pane, right-click the feature layer and click Attribute Table. In this example, the selected layer is Unique_Test.
  3. Add a Global ID field to the attribute table of the feature layer using the Add Global IDs tool. Refer to ArcGIS Pro: Find a geoprocessing tool for instructions to find and use the geoprocessing tool.
  4. Add a new field using the Add Field tool. For Field Type, select Long (32-bit integer). The unique ID numbering follows the values in this field. In this example, the HighNo field is added.
  5. Populate sequential numbers for existing features into the newly added field. In this example, sequential numbers are populated into the HighNo field.
The populated sequential numbers in the HighNo field
  1. Using a calculation rule, automatically generate a unique ID for a new feature based on a fixed prefix and the next highest existing number.
    1. In the Contents pane, right-click the layer and click Data Design > Attribute Rules. In this example, the selected layer is Unique_Test.
    2. In the Attribute Rules view, on the Calculation tab, click the Add Rule drop-down list and select Immediate Calculation.
    3. In the New Rule pane, configure the following parameters:
      1. For Rule Name, specify a name. In this example, the rule is specified as Generate_UID.
      2. For Field, select the unique ID field. In this example, the field used to store the generated IDs is UID.
      3. For Expression, insert and configure the expression below in the Expression box. Replace <Prefix> with the required prefix, <Unique ID field> with the name of the unique ID field, <Layer name> with the name of the layer, and <Sequential numbering field> with the name of the sequential numbering field created in Step 4.
var prefix = "<Prefix>";
if (!IsEmpty($feature.<Unique ID field>))
{
  return $feature.<Unique ID field>;
  }
var fs = FeatureSetByName($datastore, "<Layer name>", ["<Sequential numbering field>"], false);
var maxNum = Max(fs, "<Sequential numbering field>");
if (maxNum == null)
{
  maxNum = 0;
  }
var nextNum = maxNum + 1;
return prefix + Text(nextNum);
Expression used to automatically generate a unique ID for a new feature based on a fixed prefix and the highest existing number
      1. For Triggers, check the Insert check box.
  1. Using a calculation rule, automatically generate the next number for new features based on the highest existing number.
    1. On the Calculation tab, click the Add Rule drop-down list and select Immediate Calculation.
    2. In the New Rule pane, configure the following parameters:
      1. For Rule Name, specify a name. In this example, the rule name is specified as Calculate Highest Number.
      2. For Field, select the sequential number field. In this example, the selected field is HighNo.
      3. For Expression, insert and configure the expression below in the Expression box. Replace <Layer name> with the name of the layer and <Sequential numbering field> with the name of the sequential numbering field created in Step 4.
var fs = FeatureSetByName($datastore, "<Layer name>", ["<Sequential numbering field>"], false);
var maxNum = Max(fs, "<Sequential numbering field>");
if (maxNum == null) {maxNum = 0;}

return Number(maxNum) + 1;
Expression used to automatically generate the next number based on the highest existing number
      1. For Triggers, check the Insert check box.
  1. Use a constraint rule to prevent duplicate unique IDs.
    1. In the Attribute Rules view, click the Constraint tab and click Add Rule to create a new rule.
    2. In the New Rule pane, configure the following parameters:
      1. For Rule Name, specify a name. In this example, the rule name is specified as Remove Duplicates.
      2. For Expression, insert and configure the expression below in the Expression box. Replace <Unique ID field> with the name of the unique ID field, <GlobalID> with the name of the GlobalID field, and <Layer name> with the name of the layer.
if (IsEmpty($feature.<Unique ID field>))
{
  return true;
  }
  
var currentGuid = $feature.<GlobalID>;
var fs = FeatureSetByName($datastore, "<Layer name>", ["<Unique ID field>","<GlobalID>"], false);

for (var row in fs)
{
  if (
    row.UID == $feature.<Unique ID field> &&
    row.GlobalID != currentGuid)
    {
      return false;
      }
}

return true;
The expression used in this example
      1. For Triggers, check the Insert and Update check boxes.
      2. For Error, specify a value in the Error Number box and enter descriptive text for Error Message. In this example, the error number is specified as 1, and the error message is specified as “Duplicate”.
  1. On the Attribute Rules tab, in the Manage Edits group, click Save to save the attribute rules.

The attribute table below shows the newly populated unique IDs when a new feature is created, with each ID containing a prefix and sequential number based on the values in the feature numbering field.

The populated unique IDs in the attribute table
When a duplicate value is entered manually, the error message below is displayed. After clicking OK, the value in the field is automatically changed to a valid value.
The error message

Article ID: 000043356

Software:
  • ArcGIS Pro

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options