Generate ID Attribute Rule (Data Management)

Summary

Creates an attribute rule that generates a unique value for a field from a query. The tool outputs a .csv file containing an ArcGIS Arcade attribute rule based on the inputs provided, a Python file that contains the code for generating sequences in the workspace, and an ID file for visualizing generated IDs.

Usage

  • The Output Folder parameter specifies the location where a folder will be created using the name of the input feature class. The output .csv file containing the attribute rule will use the name of the Input Table parameter value. If the tool is run multiple times, additional .csv files will be created in the folder.

  • After the tool runs, import the attribute rule and apply it to the dataset. If the dataset is in an enterprise geodatabase, you must be the data owner to apply the output template attribute rule.

    Learn more about importing attribute rules

Parameters

LabelExplanationData Type
Input Table

The dataset that the new rule will be applied to.

Table View
Output Folder

The folder where the output .csv file will be saved. The name of the file will be taken from the Input Table parameter value.

Folder
Field

The name of the existing field the rule will be applied to.

Field
Expression
(Optional)

An SQL expression that limits the rows that the attribute rule will be applied to.

SQL Expression
Create Sequences
(Optional)

Specifies whether database sequences will be created in the specified workspace.

  • Checked—Database sequences will be created. This is the default.
  • Unchecked—Database sequences will not be created.

Boolean
Definition Type
(Optional)

Specifies the method that will be used to define the format of the ID.

  • Builder The ID format will be constructed using the ID Builder parameter.
  • TableThe ID format will be defined from a table using the ID Definition Table parameter.
  • Code Values A configuration entry and sequence will be generated for each combination of coded values from the selected fields.
  • Builder The ID format will be constructed using the id_builder parameter.
  • TableThe ID format will be defined from a table using the id_table parameter.
  • Code Values A configuration entry and sequence will be generated for each combination of coded values from the selected fields.
String
ID Builder
(Optional)

A set of format options that will define the attribute rule. This includes an SQL expression that will be used to apply different formats and sequences per asset, as well as padding, prefix, and suffix values.

  • Filter SQL—An optional SQL expression that will be used to determine whether the sequence will be applied to the row.
  • Description—An optional description of the entry that will be added to the rule settings in the attribute rule.
  • Sequence Name—The name that will be assigned to the database sequence. For enterprise geodatabases, the name must meet sequence name requirements for the database platform you're using and must be unique in the database. For file geodatabases, the name must be unique to the file geodatabase.
  • Starting Value—The starting number of the sequence. If you do not provide a starting number, the sequence will start at 1. If you do provide a starting number, it must be greater than 0.
  • Increment Value—Describes how the sequence numbers will be incremented. For example, if the sequence starts at 10 and the increment value is 5, the next value in the sequence is 15, and the next value after that is 20. If you do not specify an increment value, sequence values will increment by 1.
  • Prefix—An optional string or value that will be placed before the sequence value.
  • Suffix—An optional string or value that will be placed after the sequence value.
  • Padding—An optional positive number that represents the number of digits, where zeros will be used to fill the unused digits. For example, a value of 5 will represent the sequence value of 1 as 00001.
  • Separator—An optional value that will be used to join the prefix, sequence, and suffix.

A preview of the string will display in the Geoprocessing pane from the values entered in the format options.

Value Table
ID Definition Table
(Optional)

A table or record set that defines the ID format. This includes the SQL expression that will be used to apply different formats and sequences per asset, as well as padding, prefix, and suffix values.

The table must include the following fields:

  • WhereClause—An optional SQL expression that will be used to determine whether the sequence will be applied to the row.
  • Description—An optional description of the entry that will be added to the rule settings in the attribute rule.
  • SequenceName—The name that will be assigned to the database sequence. For enterprise geodatabases, the name must meet sequence name requirements for the database platform you're using and must be unique in the database. For file geodatabases, the name must be unique to the file geodatabase.
  • StartingValue—The starting number of the sequence. If you do not provide a starting number, the sequence will start at 1. If specified, the starting number must be greater than 0.
  • IncrementValue—Describes how the sequence numbers will increment. For example, if the sequence starts at 10 and the increment value is 5, the next value in the sequence will be 15, and the next value after that will be 20. If you do not specify an increment value, sequence values will increment by 1.
  • Prefix—An optional string or value that will be placed before the sequence value.
  • Suffix—An optional string or value that will be placed after the sequence value.
  • Padding—An optional positive number that represents the number of digits, where zeros will be used to fill the unused digits. For example, a value of 5 will represent the sequence value of 1 as 00001.
  • Separator—An optional value that will be used to join the prefix, sequence, and suffix.

Record Set
Coded Value Fields
(Optional)

The fields that will be used to generate an SQL expression and configuration for an ID.

Field

Derived Output

LabelExplanationData Type
Output Rule CSV

The output .csv file containing an Arcade attribute rule based on the inputs provided. This file is used to import the attribute rule to the dataset.

File
ID Definition Table

A table of the sequence definition configurations. This file can be edited and reused by the tool using the Definition Type parameter's Table option.

File
Python Sequence Script

The output Python sequence file. The file can be used in other workspaces or by anyone with permissions to create database sequences.

File

arcpy.management.GenerateIDAttributeRule(in_table, out_folder, field, {where_clause}, {create_seq}, {definition_method}, {id_builder}, {id_table}, {id_coded_value})
NameExplanationData Type
in_table

The dataset that the new rule will be applied to.

Table View
out_folder

The folder where the output .csv file will be saved. The name of the file will be taken from the in_table parameter value.

Folder
field

The name of the existing field the rule will be applied to.

Field
where_clause
(Optional)

An SQL expression that limits the rows that the attribute rule will be applied to.

SQL Expression
create_seq
(Optional)

Specifies whether database sequences will be created in the specified workspace.

  • CREATEDatabase sequences will be created. This is the default.
  • NO_CREATEDatabase sequences will not be created.
Boolean
definition_method
(Optional)

Specifies the method that will be used to define the format of the ID.

String
id_builder
[id_builder,...]
(Optional)

A set of format options that will define the attribute rule. This includes an SQL expression that will be used to apply different formats and sequences per asset, as well as padding, prefix, and suffix values.

  • Filter SQL—An optional SQL expression that will be used to determine whether the sequence will be applied to the row.
  • Description—An optional description of the entry that will be added to the rule settings in the attribute rule.
  • Sequence Name—The name that will be assigned to the database sequence. For enterprise geodatabases, the name must meet sequence name requirements for the database platform you're using and must be unique in the database. For file geodatabases, the name must be unique to the file geodatabase.
  • Starting Value—The starting number of the sequence. If you do not provide a starting number, the sequence will start at 1. If you do provide a starting number, it must be greater than 0.
  • Increment Value—Describes how the sequence numbers will be incremented. For example, if the sequence starts at 10 and the increment value is 5, the next value in the sequence is 15, and the next value after that is 20. If you do not specify an increment value, sequence values will increment by 1.
  • Prefix—An optional string or value that will be placed before the sequence value.
  • Suffix—An optional string or value that will be placed after the sequence value.
  • Padding—An optional positive number that represents the number of digits, where zeros will be used to fill the unused digits. For example, a value of 5 will represent the sequence value of 1 as 00001.
  • Separator—An optional value that will be used to join the prefix, sequence, and suffix.

Value Table
id_table
(Optional)

A table or record set that defines the ID format. This includes the SQL expression that will be used to apply different formats and sequences per asset, as well as padding, prefix, and suffix values.

The table must include the following fields:

  • WhereClause—An optional SQL expression that will be used to determine whether the sequence will be applied to the row.
  • Description—An optional description of the entry that will be added to the rule settings in the attribute rule.
  • SequenceName—The name that will be assigned to the database sequence. For enterprise geodatabases, the name must meet sequence name requirements for the database platform you're using and must be unique in the database. For file geodatabases, the name must be unique to the file geodatabase.
  • StartingValue—The starting number of the sequence. If you do not provide a starting number, the sequence will start at 1. If specified, the starting number must be greater than 0.
  • IncrementValue—Describes how the sequence numbers will increment. For example, if the sequence starts at 10 and the increment value is 5, the next value in the sequence will be 15, and the next value after that will be 20. If you do not specify an increment value, sequence values will increment by 1.
  • Prefix—An optional string or value that will be placed before the sequence value.
  • Suffix—An optional string or value that will be placed after the sequence value.
  • Padding—An optional positive number that represents the number of digits, where zeros will be used to fill the unused digits. For example, a value of 5 will represent the sequence value of 1 as 00001.
  • Separator—An optional value that will be used to join the prefix, sequence, and suffix.

Record Set
id_coded_value
[id_coded_value,...]
(Optional)

The fields that will be used to generate an SQL expression and configuration for an ID.

Field

Derived Output

NameExplanationData Type
out_rule_csv

The output .csv file containing an Arcade attribute rule based on the inputs provided. This file is used to import the attribute rule to the dataset.

File
out_id_file

A table of the sequence definition configurations. This file can be edited and reused by the tool using the definition_method parameter's TABLE option.

File
out_seq_script

The output Python sequence file. The file can be used in other workspaces or by anyone with permissions to create database sequences.

File

Code sample

GenerateIDAttributeRule example (stand-alone script)

The following stand-alone script is an example of how to use the GenerateIDAttributeRule function in a scripting environment.

# Name: GenerateIDAttributeRule_Example.py
# Description: GenerateIDAttributeRule of a template attribute rule in a file geodatabase

# Import the system modules
import arcpy

# Set local variables
in_table = "C:/data/data.gdb"
out_folder = "C:/out/"
field = "ID"
where_clause = ""
create_seq = "CREATE"
definition_method = "BUILDER"
id_builder = "# # 2 2 # # # #"
id_table = r"in_memory\record_set1"
id_coded_value_fields = None

arcpy.management.GenerateIDAttributeRule(
   in_table,
   out_folder,
   field,
   where_clause,
   create_seq,
   definition_method,
   id_builder,
   id_table,
   coded_value_fields
)

Environments

This tool does not use any geoprocessing environments.

Licensing information

  • Basic: No
  • Standard: Yes
  • Advanced: Yes

Related topics