HOW TO

Generate incremental IDs with domain name prefixes using Arcade in the ArcGIS Enterprise portal and ArcGIS Online

Last Published: August 20, 2024

Summary

An Arcade expression can generate incremental IDs with a domain name prefix in the attribute table of a feature layer in the ArcGIS Enterprise portal and ArcGIS Online. This is useful for unique identification, as each record has a distinctive identifier to enhance the additional context of the data.

This article provides the workflow to generate incremental IDs with domain name prefixes using Arcade in the ArcGIS Enterprise portal and ArcGIS Online.

Procedure

  1. Log in to the ArcGIS Enterprise portal or ArcGIS Online and click Content > My Content.
  2. Click the hosted feature layer to open the item details page.
  3. Add a new field. Refer to Portal for ArcGIS: Add a field or ArcGIS Online: Add a field for instructions. In this example, a new field, ‘ID’, is added to the attribute table.
  4. Calculate the field values to generate the incremental IDs with the domain name prefix using Arcade. In this example, the ID field is selected. Refer to Portal for ArcGIS: Calculate values for a field or ArcGIS Online: Calculate values for a field from the item page for instructions.
The ID field to generate the incremental IDs with the domain name prefix
  1. In the Expression box, specify the following Arcade expression:
    1. Define the base ID starting value for each domain name. In this example, the domain names are DomainA, DomainAA, DomainB, and DomainBB.
var baseID = {
    "DomainA": 1,
    "DomainAA": 2,
    "DomainB": 3,
    "DomainBB": 4
};
    1. Retrieve the current domain name. Replace <DomainName> with the field name of the domain.
var domainName = $feature.<DomainName>;
    1. Check if the domain name exists in the dictionary.
if (HasKey(baseID, domainName)) {
    var currentBaseID = baseID[domainName];
    1. Update the base ID in the dictionary for the next feature.
    baseID[domainName] = currentBaseID + 1;
    1. Format the new ID with leading zeros and a domain name.
    var formattedID = Text(currentBaseID, '000');
    return domainName + "_w_" + formattedID;
} else {
    return domainName + "_w_" + "000";
}

The code block below shows an example of the full working script.

var baseID = {
    "DomainA": 1,
    "DomainAA": 2,
    "DomainB": 3,
    "DomainBB": 4
};

var domainName = $feature.DomainName;

if (HasKey(baseID, domainName)) {
    var currentBaseID = baseID[domainName];

    baseID[domainName] = currentBaseID + 1;

    var formattedID = Text(currentBaseID, '000');
    return domainName + "_w_" + formattedID;
} else {
    return domainName + "_w_" + "000";
}
  1. Click OK.

The image below shows the incremental IDs with the domain name prefix generated in the attribute table.

The incremental IDs with the domain name prefix is generated in the attribute table

Article ID: 000033269

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS Enterprise 11 1
  • ArcGIS Enterprise 11 3
  • ArcGIS Enterprise 11 2

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options