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 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.
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 edit 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.
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.
Batch calculation rules are configured as the data owner by accessing the dataset from an enterprise geodatabase database connection. After rules are configured, they must be shared as web feature layers to be consumed via services. Editing and rule evaluation occur at the service level using the web feature layer.
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. The data source must be from a feature service that has the Validation capability enabled.
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.
The following are examples of calculation attribute rules:
- Concatenate an array of text field values into a specified field.
- When a pipe's LifeCycleStatus 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 new assetID based on a sequence.