Hi - I would love some help please. I'm trying to write an attribute rule on a relationship class that will update an attribute on the parent record if the most recent child record is updated. The parent class is sampling sites and the child class is samples. So if an attribute on the most recent sample is set (Public_sample_date attribute), then the attribute on the site itself should be updated too. But I'm getting an error....
I am getting this error...

My code is below...
//Check if the updated Sample Record is valid
if ($feature.invalid_result == 'Yes') {
return;
}
// Get the parent feature (should be just one)
var parent = First(FeatureSetByRelationshipName($feature, "Bathing_Water_Sites_SampleResults",["water_quality_indicator"], false));
// Exit if no parent found
if (IsEmpty(parent)) {
return;
}
// Get all children related to that parent
var children = FeatureSetByRelationshipName(parent, "Bathing_Water_Sites_SampleResults",["Public_sample_date","water_quality_indicator"], false);
// Initialize most recent timestamp and result
var latestDate = Date(1900, 1, 1); // Arbitrary old date
var latestWQI = null;
var thisfeaturedate = $feature.Public_sample_date
// Loop through children to find the most recently updated one
for (var child in children) {
if (!IsEmpty(child.Public_sample_date) && child.Public_sample_date > latestDate) {
latestDate = child.Public_sample_date;
latestWQI = child.water_quality_indicator;
}
}
// Exit if the updated feature is not the latest one
if (thisfeaturedate < latestDate) {
return;
}
// Proceed if parent exists
if (!IsEmpty(parent)) {
// Update the parent's water_quality_indicator with the water_quality_indicator of the most recent sample record
return {
'edit': [{
'className': 'Bathing_Water_Sites',
'updates': [{
'objectID': parent.OBJECTID,
'attributes': {
'water_quality_indicator': latestWQI
}
}]
}]
};
}