Amazing! Thank you.
I was starting to come to this conclusion yesterday but I could not quite figure out how to "word" the filter and just kept getting errors. Works great now and I have duplicated it to provide the totals for all of our different statuses into the parent field.
var child_fs = FeatureSetByRelationshipName($feature, "ApplicationSite_TurfArea", ['Area', 'Status'])
var filterd_child_fs = Filter(child_fs, "Status = 2")
if(filterd_child_fs == null) { return }
return Sum(filterd_child_fs, "Area")
With the help of this blog https://github.com/Esri/arcade-expressions/blob/master/attribute_rule_calculation/UpdateParentFeatur... I was also able to add an event to the child fields to trigger the recalculation if only they were edited and not the parent field.
// This rule will update an attribute in the parent feature
// Store the parent feature global from the key field in the relationship
var parent_id = $feature.GUIDApplicationSite;
if (IsEmpty(parent_id))
return parent_id;
// force to upper as the sql is case sensitive
parent_id = Upper(parent_id);
// Using the GDB name, get the parent classes records and Global ID field
var parent_class = FeatureSetByName($datastore, "ApplicationSite", ["globalid", 'laststatus'], false);
// Filter the parent class for only related features
var parent_records = Filter(parent_class, "globalid = @parent_id");
var updates = [];
var i = 0;
var new_value = 0;
if (IsEmpty($feature.Status) == False)
{
new_value = $feature.Status
}
// Loop through each feature, create a dict of the Global ID and the new value date
for (var row in parent_records) {
// If the parent row is null or has a different value, updated it
if (IsEmpty(row['laststatus']) || row['laststatus'] != new_value)
{
updates[i++] = {
'globalid': parent_id,
'attributes': {"laststatus": new_value}
};
}
}
// Return the original value in the result parameter, as to not lost the entered value
// Using the edit parameter, return the class and list of updates
return {
'result': parent_id,
'edit': [
{'className': 'ApplicationSite',
'updates': updates
}
]
};
I probably could have simplified it better since I am not looking through multiple fields to get the status but it all seems to work very nicely now.
I am a little curious what will happen to all this when I transfer it to AGOL so it can be used in field maps LOL but I guess I will find out soon enough.
Thank you, again.