Hi there,
I have a 1:M relationship between Manholes (parent) and Inspections (child). I'd like for when a new inspection is submitted, that the condition values of the most recent inspection write to the Manhole. For example, I have a field called "Cover_Condition" in the inspection table, and a field called "Cover_Condition" in the Manhole and here is the Arcade I have so far (This rule is assigned to the Cover_Condition field and triggered on insert, update, and delete, and it is excluded from application evaluation):
//Forgein Key in child table
var fk = $feature.ParentGUID_
//Load all inspections of the feature
var inspections = FeatureSetByName($datastore, "DBO.SanitaryManholeInspections",['ParentGUID_', 'Date_Time', 'Cover_Condition'], false)
var related_inspections = Filter(inspections, 'ParentGUID_ = ')
//Filter out record if delete trigger
if($editcontext.editType == "DELETE") {
var pk = $feature.GlobalID_1
related_inspections = Filter(related_inspections, "GlobalID_1 <> ")
}
//Filter most recent inspection date
var last_inspection = First(OrderBy(related_inspections, "Date_Time DESC"))
//Return nothing if no records found
if(IsEmpty(last_inspection)){
return ;
}
//Update Cover_Condition field in parent feature class
return {
"result": fk,
"edit": [{
"className" : "DBO.ssManhole_z",
"updates": [{
//selecting the parent feature to update
"GlobalID" : last_inspection.ParentGUID_,
//Update the Cover_Condition field in parent feature class
"attributes" : {'Cover_Condition': last_inspection.Cover_Condition
}
}]
}]
};
The expression evaluates as valid in the expression editor, but when I test in Field Maps, I get the error "Unable to complete operation. Unable to perform applyEdits operation. Error: Invalid column value [Invalid column value] [Cover_Condition]."
I did check the spelling and the field names in both the Manholes and Inspection Table are spelled that way.
I also get confused when writing expressions like this which field I should assign the rule to, or can it be left blank?
Thank you!!