Add Attribute Rule (Data Management)

Summary

Adds an attribute rule to a dataset.

Attribute rules are user-defined rules that can be added to a dataset to enhance the editing experience and help enforce data integrity. These rules can be used to populate attribute values or constrain permissible feature configurations and are enforced during feature editing. If a rule is violated when editing a feature, an error message will be returned.

Learn more about attribute rules

Learn about the ArcGIS Arcade scripting language

Usage

  • Batch calculation and validation rules in an enterprise geodatabase are evaluated using the validation server for datasets that are branch versioned. To add these rule types, the database connection must have Versioning Type set to Branch.

  • The dataset must have a GlobalID field.

  • To add batch calculation or validation rules to a dataset, editor tracking must be enabled.

  • The expression used to define an attribute rule is limited to the functionality available using the Arcade language.

  • You can reference a database sequence created by the Create Database Sequence tool using the NextSequenceValue Arcade data function for the Script Expression parameter.

  • To transfer existing attribute rules to another dataset, you can use the Export Attribute Rules and Import Attribute Rules tools instead of running this tool multiple times.

  • Note:

    Once you add attribute rules to a dataset, the minimum client version for the dataset is ArcGIS Pro 2.1. This means that the dataset will no longer be available for use in ArcMap.

Parameters

LabelExplanationData Type
Input Table

The table or feature class that will have the new rule applied.

Table View
Name

A unique name for the new rule.

String
Type

Specifies the type of attribute rule that will be added.

  • CalculationAttribute values will be automatically populated for features when another attribute is set on a feature. These rules are applied based on the triggering events specified. Long running calculations can be set to run in batch mode and will be evaluated at a user-defined time.When adding multiple calculation rules, the order in which the rules are added is important if there are circular dependencies. For example, Rule A calculates Field1 is equal to the value of $feature.Field2 + $feature.Field3, and Rule B calculates Field4 is equal to $feature.Field1 + $feature.Field5; the results of the calculation may be different depending on the order the rules are added.
  • ConstraintPermissible attribute configurations will be specified on a feature. When the constraint rule is violated, an error is generated and the feature is not stored. For example, if the value of Field A must be less than the sum of Field B and Field C, an error will be generated when that constraint is violated.
  • ValidationExisting features will be identified with a batch validation process. Rules are evaluated at a user-defined time. When a rule is violated, an error feature is created.
String
Script Expression

The Arcade expression that defines the rule.

Calculator Expression
Is Editable
(Optional)

Specifies whether the attribute value can be edited. Attribute rules can be configured to either block or allow editors to edit the attribute values of the field being calculated. This parameter is only applicable for the calculation attribute rule type.

  • Checked—The attribute value can be edited. This is the default.
  • Unchecked—The attribute value cannot be edited.

Boolean
Triggering Events
(Optional)

Specifies the editing events that will trigger the attribute rule to take effect. This parameter is valid for calculation and constraint rule types only. At least one triggering event must be provided for calculation rules in which the Batch parameter is unchecked. Triggering events are not applicable for calculation rules that have the Batch parameter checked.

  • InsertThe rule will be applied when a new feature is added.
  • UpdateThe rule will be applied when a feature is updated.
  • DeleteThe rule will be applied when a feature is deleted.
String
Error Number
(Optional)

An error number that will be returned when this rule is violated. This value is not required to be unique, so the same custom error number may be returned for multiple rules.

This parameter is required for the constraint and validation rule types. It is optional for the calculation rule type.

String
Error Message
(Optional)

An error message that will be returned when this rule is violated. It is recommended that you use a descriptive message to help the editor understand the violation when it occurs. The message is limited to 256 characters.

This parameter is required for the constraint and validation rule types. It is optional for the calculation rule type.

String
Description
(Optional)

The description of the new attribute rule. The description is limited to 256 characters.

String
Subtype
(Optional)

The subtype to which the rule will be applied if the dataset has subtypes.

String
Field
(Optional)

The name of an existing field to which the rule will be applied. This parameter is only applicable for the calculation attribute rule type.

String
Exclude from application evaluation
(Optional)

Specifies whether the application will evaluate the rule locally before applying the edits to the workspace.

Not all clients have the capability to run all of the available rules, so authors can exclude certain rules from client evaluation. For example, some rules may refer to data that has not been made available to all clients (reasons can include the data is offline, size, or security), or some rules may depend on the user or context (that is, a lightweight field update in a data collection app may not run a rule that requires additional user input or knowledge; however, a client such as ArcGIS Pro may support it).

This parameter is not applicable for validation rule or calculation rule types if the Batch parameter is checked.

  • Checked—The rule will be excluded from client evaluation.
  • Unchecked—The rule will not be excluded from client evaluation. This is the default.

Note:

For versions earlier than ArcGIS Pro 2.4, this parameter was labeled Server only.

Boolean
Batch
(Optional)

Specifies whether the rule evaluation will be run in batch mode.

  • Checked—The rule evaluation will be run in batch mode at a later time by running validate.
  • Unchecked—The rule evaluation will not be run in batch mode. Triggering events will be used to determine when the rule is evaluated for insert, update, or delete edit operations. This is the default.

For calculation rules, this parameter can be checked or unchecked. For validation rules, this parameter must be unchecked. For constraint rules, this parameter must be unchecked.

Boolean
Severity
(Optional)

The severity of the error.

A value within the range of 1 through 5 can be chosen to define the severity of the rule. A value of 1 is high, being the most severe, and a value of 5 is low, being the least severe. For example, you can provide a low severity for a specific attribute rule and ignore the error during data production workflows, or set a high severity in which the error must be fixed for accuracy of the data collected.

This parameter is only applicable to validation rules.

Long
Tags
(Optional)

A set of tags that identify the rule (for searching and indexing) as a way to map to a functional requirement in a data model.

String
Triggering Fields
(Optional)

A list of fields that will trigger an attribute rule to run when an editing event occurs during an update trigger for calculation and constraint attribute rules. If no fields are specified, the tool will use all fields. This is default.

To enter multiple triggering fields, use a semicolon delimiter, for example, Field1;Field2;Field3.

String

Derived Output

LabelExplanationData Type
Attribute Rule Added

The updated input table with an attribute rule added.

Table View

arcpy.management.AddAttributeRule(in_table, name, type, script_expression, {is_editable}, {triggering_events}, {error_number}, {error_message}, {description}, {subtype}, {field}, {exclude_from_client_evaluation}, {batch}, {severity}, {tags}, {triggering_fields})
NameExplanationData Type
in_table

The table or feature class that will have the new rule applied.

Table View
name

A unique name for the new rule.

String
type

Specifies the type of attribute rule that will be added.

  • CALCULATIONAttribute values will be automatically populated for features when another attribute is set on a feature. These rules are applied based on the triggering events specified. Long running calculations can be set to run in batch mode and will be evaluated at a user-defined time.When adding multiple calculation rules, the order in which the rules are added is important if there are circular dependencies. For example, Rule A calculates Field1 is equal to the value of $feature.Field2 + $feature.Field3, and Rule B calculates Field4 is equal to $feature.Field1 + $feature.Field5; the results of the calculation may be different depending on the order the rules are added.
  • CONSTRAINTPermissible attribute configurations will be specified on a feature. When the constraint rule is violated, an error is generated and the feature is not stored. For example, if the value of Field A must be less than the sum of Field B and Field C, an error will be generated when that constraint is violated.
  • VALIDATIONExisting features will be identified with a batch validation process. Rules are evaluated at a user-defined time. When a rule is violated, an error feature is created.
String
script_expression

The Arcade expression that defines the rule.

Calculator Expression
is_editable
(Optional)

Specifies whether the attribute value can be edited. Attribute rules can be configured to either block or allow editors to edit the attribute values of the field being calculated. This parameter is only applicable for the calculation attribute rule type.

  • EDITABLEThe attribute value can be edited. This is the default.
  • NONEDITABLEThe attribute value cannot be edited.
Boolean
triggering_events
[triggering_events,...]
(Optional)

Specifies the editing events that will trigger the attribute rule to take effect. This parameter is valid for calculation and constraint rule types only. At least one triggering event must be provided for calculation rules in which the batch parameter is set to NOT_BATCH. Triggering events are not applicable for calculation rules that have the batch parameter set to BATCH.

  • INSERTThe rule will be applied when a new feature is added.
  • UPDATEThe rule will be applied when a feature is updated.
  • DELETEThe rule will be applied when a feature is deleted.
String
error_number
(Optional)

An error number that will be returned when this rule is violated. This value is not required to be unique, so the same custom error number may be returned for multiple rules.

This parameter is required for the constraint and validation rule types. It is optional for the calculation rule type.

String
error_message
(Optional)

An error message that will be returned when this rule is violated. It is recommended that you use a descriptive message to help the editor understand the violation when it occurs. The message is limited to 256 characters.

This parameter is required for the constraint and validation rule types. It is optional for the calculation rule type.

String
description
(Optional)

The description of the new attribute rule. The description is limited to 256 characters.

String
subtype
(Optional)

The subtype to which the rule will be applied if the dataset has subtypes.

String
field
(Optional)

The name of an existing field to which the rule will be applied. This parameter is only applicable for the calculation attribute rule type.

String
exclude_from_client_evaluation
(Optional)

Specifies whether the application will evaluate the rule locally before applying the edits to the workspace.

Not all clients have the capability to run all of the available rules, so authors can exclude certain rules from client evaluation. For example, some rules may refer to data that has not been made available to all clients (reasons can include the data is offline, size, or security), or some rules may depend on the user or context (that is, a lightweight field update in a data collection app may not run a rule that requires additional user input or knowledge; however, a client such as ArcGIS Pro may support it).

This parameter is not applicable for validation rule or calculation rule types if the batch parameter is set to BATCH.

  • EXCLUDEThe rule will be excluded from client evaluation.
  • INCLUDEThe rule will not be excluded from client evaluation. This is the default.
Boolean
batch
(Optional)

Specifies whether the rule evaluation will be run in batch mode.

  • BATCHThe rule evaluation will be run in batch mode at a later time by running validate.
  • NOT_BATCHThe rule evaluation will not be run in batch mode. Triggering events will be used to determine when the rule is evaluated for insert, update, or delete operations. This is the default.

For calculation rules, this parameter value can be BATCH or NOT_BATCH. For validation rules, this parameter value must be BATCH. For constraint rules, this parameter value must be NOT_BATCH.

Boolean
severity
(Optional)

The severity of the error.

A value within the range of 1 through 5 can be chosen to define the severity of the rule. A value of 1 is high, being the most severe, and a value of 5 is low, being the least severe. For example, you can provide a low severity for a specific attribute rule and ignore the error during data production workflows, or set a high severity in which the error must be fixed for accuracy of the data collected.

This parameter is only applicable to validation rules.

Long
tags
[tags,...]
(Optional)

A set of tags that identify the rule (for searching and indexing) as a way to map to a functional requirement in a data model. To enter multiple tags, use a semicolon delimiter, for example, Tag1;Tag2;Tag3.

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

A list of fields that will trigger an attribute rule to run when an editing event occurs during an update trigger for calculation and constraint attribute rules. If no fields are specified, the tool will use all fields. This is default.

To enter multiple triggering fields, use a semicolon delimiter, for example, Field1;Field2;Field3.

String

Derived Output

NameExplanationData Type
out_table

The updated input table with an attribute rule added.

Table View

Code sample

AddAttributeRule example 1 (Python window)

Add a calculation rule that calculates the labeltext field of the GasPipes feature class.

'''****************************************************************************
Name:        AddAttributeRule_example1.py
Description: This script adds a calcualtion rule to a feature class
Created by:  Esri
****************************************************************************'''

# Import required modules        
import arcpy

# Set local variables
in_table = "C:\\MyProject\\sdeConn.sde\\progdb.user1.GasPipes"
name = "calculateRuleLabel"
script_expression = 'if ($feature.material == 5) {return "Plastic"} else {return "Other"}'
triggering_events = "INSERT;UPDATE"
description = "Populate label text"
subtype = "Coated Steel"
field = "labeltext"

# Run the AddAttributeRule tool
arcpy.management.AddAttributeRule(in_table, name, "CALCULATION", script_expression, "EDITABLE", triggering_events, "", "", description, subtype, field)
AddAttributeRule example 2 (Python window)

Add a constraint rule that limits the operating pressure attribute of the GasPipes feature class to 300.

'''****************************************************************************
Name:        AddAttributeRule_example2.py
Description: This script adds a constraint rule to a feature class
Created by:  Esri
****************************************************************************'''

# Import required modules        
import arcpy

# Set local variables
in_table = "C:\\MyProject\\sdeConn.sde\\progdb.user1.GasPipes"
name = "constraintRuleOP"
script_expression = '$feature.OPERATINGPRESSURE < 300'
triggering_events = "INSERT;UPDATE"
description = "Operating pressure must be less than 300"
subtype = "ALL"
error_number = 2001
error_message = "Invalid operating pressure. Must be less than 300."

# Run the AddAttributeRule tool
arcpy.management.AddAttributeRule(in_table, name, "CONSTRAINT", script_expression, "EDITABLE", triggering_events, error_number, error_message, description, subtype)
AddAttributeRule example 3 (Python window)

Add a validation rule to the GasPipes feature class to flag existing features with an operating pressure greater than 300.

'''****************************************************************************
Name:        AddAttributeRule_example3.py
Description: This script adds a validation rule to a feature class
Created by:  Esri
****************************************************************************'''

# Import required modules        
import arcpy

# Set local variables
in_table = "C:\\MyProject\\sdeConn.sde\\progdb.user1.GasPipes"
name = "validationRuleMaxOP"
rule_type = "VALIDATION"
script_expression = "$feature.OPERATINGPRESSURE < 300"
error_number = 3001
error_message = "Maximum operating pressure exceeded"
description = "Validation rule: max operating pressure value"
subtype = "Coated Steel"
batch = "BATCH"
severity = 3
tags = "OP;MAXOP"

# Run the AddAttributeRule tool
arcpy.management.AddAttributeRule(in_table, name, rule_type, 
                                  script_expression, "", "", 
                                  error_number, error_message, 
                                  description, subtype, "", "", 
                                  batch, severity, tags)

Environments

Licensing information

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

Related topics