I have created an attribute rule for an inspection table that will update a field in the parent feature class every time the table is updated. This rule is set to run on the 'insert', 'update', and 'delete' triggers. However, it only functions properly for the 'insert' and 'update' triggers. If I delete a row from the inspection table, the rule will not re-calculate the 'date' field and will instead retain the date of the recently deleted row.
I had thought that this code was simple enough that it would just re-calculate the date field regardless of what edit actions are being performed and would keep that field up to date as a result. Any ideas why the delete action is not re-calculating the rule in the same way? Thank you!
My code:
// filter the parent class for only related features
var parent_id = $feature.GUID;
var parent_class = FeatureSetByName($datastore, "Parent_FeatureClass", ["GlobalID", "Date"], false);
var parent_match = Filter(parent_class, "GlobalID = @parent_id");
// return null if no matches are found
var cnt = Count(parent_match);
if (cnt == 0) {
return null
};
// else, order inspection records by most recent to oldest entries and retain most recent record
var tabledata = FeatureSetByName($datastore, "Inspection_Table");
var ordered_dates = OrderBy(tabledata, "Date DESC");
var relatedinfo = "";
var info = First(ordered_dates);
relatedinfo = info.Date;
// update parent table field with most recent record data
return {
"result" : $feature.GUID,
"edit": [
{
"className" : "Parent_FeatureClass",
"updates": [
{"globalID" : parent_id,
"attributes":
{
"Date" : relatedinfo
}
}
]
}
]
}