Hello. I currently have an Attribute Rule which carries over a desired value from a child field to a specified parent field (globalid to GUID, 1:M relationship class). I didn't think about the fact that when multiple child records are associated to a single parent record I need to specify which child record's value will transfer over!
I have a date field in the child table (DATE_INSPECTION) and would like to be able to bring the most recent/current date value from said field (amongst multiple child records in a 1:M relationship) over to a parent field (DATE_LAST_INSPECTION). It also needs to function if there is only one related child record. I'm not proficient enough in Arcade to figure this out. Any date-related examples I've come across are too complex for me to finagle. If someone (possibly @MikeMillerGIS coming in clutch for a second time today??) could help me out, I'd greatly appreciate it! My current code is below. Feel free to tweak it or provide something totally different that might work.
// Calculation Attribute Rule on Child
// Triggers: Insert, Update
// Field: empty
// do nothing if value did not change
if($originalfeature.CHILD_FIELD == $feature.CHILD_FIELD) { return null }
// get the feature
var TEST = First(FeatureSetByRelationshipName($feature, "OCGIS.DPW_TESTING_REL"))
if(TEST == null) { return null }
// Send a request to update the field in the parent FC
return {
"edit": [
{
"className": "PARENT_NAME",
"updates": [
{"globalID": TEST.GlobalID, "attributes": {"PARENT_FIELD": $feature.CHILD_FIELD}}
]
}
]
}