Hi all,
I'm new to attribute rules and I'm trying to figure out how to build a calculation attribute rule to update a couple fields in an external feature class based on values in a related table.
I have a Hydrant FC and a Hydrant Inspection table. These are related by way of a relationship class with an asset_id. When a user creates a new inspection or updates an existing inspection for a particular asset_id, I would like the system to take the condition_rating and inspection_date and update the corresponding recent_condition_rating and recent_inspection_date fields in the Hydrant FC for the same asset_id.
I have seen examples of updating an external FC's field via attribute rules using intersect, but I can't figure out how to do similar using non-spatial means.
Any help would be very much appreciated. Thanks in advance.
Solved! Go to Solution.
You can get related features with FeaturesetByRelationshipName() or Filter().
To update another table, you have to return a dictionary with specific keys: Attribute rule dictionary keywords—ArcGIS Pro | Documentation
// Calculation Attribute Rule on inspection table
// field: empty
// triggers: Insert, Update
// load the hydrants
var hydrant_fs = FeaturesetByName(...)
// filter for the hydrant this inspection belongs to
var asset_id = $feature.asset_id
var hydrant = First(Filter(hydrant_fs, "asset_id = @asset_id"))
// if no corresponding hydrant is found, abort
if(hydrant == null) { return }
// else update the hydrant
return {
edit: [{
className: "HydrantFC", // full name of the hydrant fc
updates: [{
objectID: hydrant.OBJECTID,
attributes: {
recent_condition_rating: $feature.condition_rating
recent_inspection_date: $feature.inspection_date
}
}]
}]
}
You can get related features with FeaturesetByRelationshipName() or Filter().
To update another table, you have to return a dictionary with specific keys: Attribute rule dictionary keywords—ArcGIS Pro | Documentation
// Calculation Attribute Rule on inspection table
// field: empty
// triggers: Insert, Update
// load the hydrants
var hydrant_fs = FeaturesetByName(...)
// filter for the hydrant this inspection belongs to
var asset_id = $feature.asset_id
var hydrant = First(Filter(hydrant_fs, "asset_id = @asset_id"))
// if no corresponding hydrant is found, abort
if(hydrant == null) { return }
// else update the hydrant
return {
edit: [{
className: "HydrantFC", // full name of the hydrant fc
updates: [{
objectID: hydrant.OBJECTID,
attributes: {
recent_condition_rating: $feature.condition_rating
recent_inspection_date: $feature.inspection_date
}
}]
}]
}
Thanks so much Johannes! I appreciate the help!
Cheers