Since version: 1.5
With the Attribute Rule Calculation profile, expressions can be written to update field values based on expression logic. This profile is used for calculation attribute rules tools in ArcGIS Pro. When the attribute rule is evaluated for a dataset, the return value for the expression is cast to the field type of the output value. It is best practice to handle casting within the script for full control of casting behavior to Number, Date, or Text return types.
Context
The following products implement this profile:
- ArcGIS Pro
- ArcGIS Enterprise
- ArcGIS Maps SDKs for Native Apps
Spatial reference
The spatial reference of the expression's data source1 determines the execution context's spatial reference.
Time zone
The time zone of the expression's data source1 determines the execution context's default time zone.
Profile variables
| Variable Name | Type | Description | Since version |
|---|---|---|---|
| $datastore | FeatureSetCollection | A collection of layers in the same feature service or database as the $feature executing the script. | 1.5 |
| $editcontext.editType | Text | Indicates whether the edit event is INSERT, UPDATE, DELETE, or NA (not applicable). | 1.10 |
| $editcontext.editTag | Text | A text value originating from an attribute rule's edit dictionary. An attribute rule expression author can set edit in a return dictionary for downstream edits triggered by attribute rules. When an edit triggers another attribute rule, the value for edit set by the rule that triggered the edit is populated here with the value. Use this with $editcontext.edit to distinguish user edits from edits made by attribute rules. The default value is "" in all Attribute rules profiles which indicates a user edit. This value may be null on other profiles. | 1.38 |
| $feature | Feature | The feature being calculated. | 1.5 |
| $originalFeature | Feature | The previous state of the feature being calculated. | 1.9 |
| $featureSet | FeatureSet | A collection of features in the same table as the $feature evaluating the expression. | 1.13 |
Function bundles
Core | Geometry | Data Access | Database
Return types
Number | Text | Date | DateOnly | Time | Dictionary
For a list of valid dictionary keywords, click here.
Example
The following expression demonstrates how to generate a unique id for each feature, if not already set.
//Define the leading text, the trailing text and the delimiter for the ID
prefix = "ABC"
join_char = "-"
suffix = "XYZ"
//Ensure the ID is not already set, if it is, return the original id
if (IsEmpty($feature.assetid)) {
// If you do not want to use a prefix, or suffix, remove it from the list
return Concatenate([prefix, NextSequenceValue("GDB_SEQUENCE_NAME"), suffix], join_char)
}
else {
return $feature.assetid
}The following expression demonstrates how to update related rows while preventing the same rule from running again on edits made by the rule.
if ($feature.common_name == $originalFeature.common_name) {
return;
}
if ($editcontext.editTag == "attribute rule") {
return;
}
var groupName = $feature.group_name;
var globalId = $feature.GlobalID;
var commonName = $feature.common_name;
var relatedRows = Filter($featureSet, "group_name = @groupName and globalid <> @globalId and (common_name <> @commonName or common_name is null)");
var updates = [];
for (var row in relatedRows) {
Push(updates, {
"globalId": row.globalid,
"attributes": {
"common_name": commonName
}
});
}
return {
"edit": [{
"className": "main.mytable",
"updates": updates,
"editTag": "attribute rule"
}]
};- Data source can be a file geodatabase, mobile geodatabase, or mobile service.