Hi ESRI Community,
I need a modification to a previous post I made. The previous solution works fine except for one part that I forgot to mention to the community and didn't catch when I tested it.
In this scenario I have a feature class that has a related table used for inspections. In the feature a have a field named "ConditionInspectionStatus" that has a default attribute of "No Inspection" at the time the record is created. In the inspection, I have a field named "InspectionReason" and the field staff selects either "Condition Rating" or "Maintenance Activity". When "Condition Rating" is selected the script runs fine, it updates the "No Inspection" with either "Inspection Completed" or "Inspection Attempted".
However, when "Maintenance Activity" is selected it overwrites whatever attribute is in the "ConditionInspectionStatus" field in the feature class with a null. I need it to not update the feature class field with anything when "Maintenance Activity" is selected in the inspection. I need it to leave whatever attribute that is in the field of the feature class alone.
I tried just commenting the null out however it gives me an Identifier expected for the right parenthese after the null line (line 12).
I apologize for not mentioning the default value in the feature class field and for not catching this sooner.
Any assistance in this matter would be greatly appreciated.
// abort if there is no ParnetGUID
var parent_id = $feature.ParentGUID
if (IsEmpty(parent_id)) { return parent_id }
// get the inspection status
var inspection_status= When(
$feature.InspectionReason == "Condition Rating" && $feature.OtherDrainageRatable == "Yes",
"Inspection Completed",
$feature.InspectionReason == "Condition Rating" && $feature.OtherDrainageRatable != "Yes",
"Inspection Attempted",
null // default value, for example when InspectionReason is not "Condition Rating"
)
// get the date field that should be updated
var date_field = When(
$feature.InspectionReason == "Condition Rating", "LastConditionRatingInspDate",
$feature.InspectionReason == "Maintenance Activity", "LastMaintenanceActivityDate",
null // some other inspection reason
)
// construct the update instructions
var update = {"globalID": parent_id, "attributes": {}}
update.attributes[date_field] = $feature.InspectionDate
update.attributes["ConditionInspectionStatus"] = inspection_status
if($feature.MaintenanceReason != null) {
update.attributes["MaintenanceActivityReason"] = $feature.MaintenanceReason
}
return {
'edit': [{
'className': 'GISTRANS_PLANNING_O.CTDOT_Planning_OtherDrainage',
'updates': [update]
}]
}