Calculation rules are used to automatically populate attribute configurations on a feature. They can be created as immediate calculation rules or batch calculation rules, depending on when the rule needs to be evaluated as follows:
- Immediate calculation rules—Rule evaluation occurs immediately during edit operations. The type of triggering event specified during rule creation allows rule evaluation to occur based on insert, update, or delete operations.
- Batch calculation rules—Rule evaluation occurs at a user-specified time.
Attribute fields associated with a calculation rule can be configured to allow user edits or to be read-only. When creating calculation rules, the Is Editable check box is available under the input field to which it applies, as follows:
- Checked—User-defined attribute edits are permitted on a field. User input for this field can be overwritten by evaluation of an attribute rule based on the rule definition.
- Unchecked—User-defined attribute edits are not permitted, and the attribute field the rule is created on is defined as a system-maintained field. The calculation rule will be applied during the triggering event defined in the rule.
Caution:
Once a user-defined field is set as system maintained, it cannot be changed.
Immediate calculation rules
Calculation rules that are evaluated during edit operations based on certain triggering events are referred to as immediate calculation rules. This type of calculation rule is used in workflows in which calculations need to be performed automatically as edits are made.
Immediate calculation rules are created in the Attribute Rules view by clicking the Calculation Rule drop-down button and clicking Immediate Calculation . This rule type can also be created using the Add Attribute Rule tool with the batch option set to false or the Import Attribute Rules tool.
Immediate calculation rules are evaluated at the time of the edit operation, based on specific triggering events. The triggering events (insert, update, or delete) are specified as a property of the rule.
Dive-in:
Direct data changes from a record being deleted might not be observed with an immediate calculation rule. But depending on the Arcade script, other advanced attribute rule functionality might be observed, such as editing another feature with the delete trigger. See Attribute rule dictionary keywords for more information.
Batch calculation rules
Calculation rules that are evaluated at a user-specified time are referred to as batch calculation rules. This type of calculation rule is designed for situations when you want to perform calculations on existing features or you need control over when the rule evaluation occurs. This could be for instances when the calculation is too expensive to be performed at the time of the edit operation.
Note:
Batch calculation and validation attribute rules are only supported on point, line, and polygon feature classes or tables.Batch calculation rules are created in the Attribute Rules view by clicking the Calculation Rule drop-down button and clicking Batch Calculation . This rule type can also be created using the Add Attribute Rule tool with the batch option set to true or the Import Attribute Rules tool.
To evaluate batch calculation rules for a dataset, you can use the Evaluate Rules tool or the Error Inspector.
Note:
The input workspace for evaluating batch calculation and validation rules depends on the type of geodatabase the dataset with attribute rules is stored in:- File or mobile geodatabase—The geodatabase is the input workspace to evaluate.
- Enterprise geodatabase—You must use a feature service with the Validation capability as the input workspace to evaluate. Learn more about sharing data as a feature service with the Validation capability.
The following are the general steps involved in configuring and evaluating batch calculation rules:
- Add the attribute rule to the dataset.
- Share the dataset as a web feature layer with the Validation capability enabled.
- Make edits to the web feature layer.
- Evaluate the rules and check features using the Error Inspector.
- Review the error features and make edits to correct the errors.
- Evaluate the rules.
To learn more, see Share datasets with attribute rules, Evaluate attribute rules, and Manage attribute rule errors.
Evaluation order
When rules are evaluated, the order controls the sequence in which rules are evaluated. For calculation rules, the order in which rules are evaluated on a dataset is important, as this can cause the result of the rule evaluation to differ.
The evaluation order is important when there are dependencies from other fields being calculated for the feature being stored. The following image illustrates how the result of the two calculation rules can vary depending on the evaluation order of the rules:
The evaluation order is a property of an attribute rule that can be viewed using the Attribute Rules view, or the arcpy.Describe function can be used to print the attribute rule properties. The evaluation order is initially determined by the order in which rules are created for a dataset and is stored as an integer value that starts with a value of 1. The order increases by one as new rules are created. Immediate and batch calculation rules independently maintain their own evaluation order.
The Attribute Rules view lists calculation rules based on the evaluation order in the Immediate and Batch sections. To make changes to the evaluation order, edit the Order column in the Attribute Rules view or use the Reorder Attribute Rule tool.
When a dataset contains multiple attribute rules, the execution also follows a specific order depending on the rule type. See Evaluate attribute rules for more information.
Examples
The following are examples of how calculation attribute rules can be used in a geodatabase:
- Concatenate an array of text field values into a specified field.
- When a pipe's LifeCycleStatus attribute is updated to Abandoned, the PressureZone attribute is updated to None.
- When a power pole has a length greater than 65 feet, the material value will be calculated as steel.
- When a new pole is created, generate a text value based on the sequence assetid_seq.
Tip:
When creating calculation rules, ensure the script expression results are using the same data type as the field being calculated.See the Arcade profile for the requirements and global variables to author attribute rule types. The Arcade Getting Started guide and Function Index are additional resources you can use to construct script expressions for attribute rules.