Hi ESRI Community,
After 8 weeks I was finally able to look at this problem and I still can't get the last step to work. I want to thank those who have helped me so far as we are very close to having this working.
I modified the original script to accommodate my real data versus my test data.
I am using Enterprise 10.9.1 and Pro 2.8.8. The inspection is done in Field Maps.
I have a feature class with the following fields that participate in the script:
ConditionRatingInspectStatus - When a new record is created it has a default value of "No Inspection".
LastConditionRatingInspectDate - This gets populated when there is a Condition Rating inspection.
MaintenanceActivityReason - When a new record is created it has a default value of "No Maintenance Activity".
LastMaintenanceActivityDate - This gets populated when there is a Maintenance Activity inspection.
There will almost always be a Condition Rating inspection before there is a Maintenance Activity inspection.
I have an inspection table with the following fields that participate with the script:
InspectionDate - This field automatically gets populated when a record is created.
InspectionReason - Dropdown with two choices - "Condition Rating" or "Maintenance Activity"
ManholeRatable - Dropdown with several choices, however, we focus on "Yes". This means that the inspector was able to conduct a full inspection.
The script works like this:
When the Inspection Reason is "Condition Rating" and Manhole Ratable is "Yes", then in the feature the ConditionRatingInspectStatus field is updated with "Inspection Completed" and the LastConditionRatingInspectDate is populated with the InspectionDate. THIS WORKS.
When the Inspection Reason is "Condition Rating" and Manhole Ratable is not "Yes", then in the feature the ConditionRatingInspectStatus field is updated with "Inspection Attempted" and the LastConditionRatingInspectDate is populated with the InspectionDate. THIS WORKS
When the Inspection Reason is "Maintenance Activity" I need to make sure that the latest data in the ConditionRatingInspectStatus and the LastConditionRatingDate are NOT overwritten.
In FIELD MAPS, when the Inspection Reason is "Maintenance Activity" is submitted, I get an error that states:
Arcade error: String type expected Script line 24.
If anyone has any suggestions, I would greatly appreciate them as I am not knowledgeable in Arcade. Again, thank you to those who have helped me get this far.
// abort // abort if there is no ParentGUID
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.ManholeRatable == "Yes", "Inspection Completed",
$feature.InspectionReason == "Condition Rating" && $feature.ManholeRatable != "Yes", "Inspection Attempted",
$feature.InspectionReason == "Maintenance Activity", $feature.ConditionRatingInspectStatus, 'valueifnomatch' )
// get the date field that should be updated
var date_field = When(
$feature.InspectionReason == "Condition Rating", "LastConditionRatingInspectDate",
$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["ConditionRatingInspectStatus"] = inspection_status
if($feature.MaintenanceReason != null) {
update.attributes["MaintenanceActivityReason"] = $feature.MaintenanceReason
}
return {
'edit': [{
'className': 'GISTRANS_PLANNING_O.CTDOT_Planning_Manholes',
'updates': [update]
}]
}
It is possible for date_field to be null which would explain that error, although it's on line 23. I would add an IsEmpty check to make sure date_field is not null.
Thank you for your reply and I apologize for my ignorance with Arcade.
In the Arcade scripts I have for this the InspectionDate field is calculated prior to the script noted above is triggered.
The var date_field, which is derived from the Inspection Reason field will always have an attribute, either "Condition Rating" or "Maintenance Activity". In Field Maps is will be set as a required field forcing an attribute to be selected. However, you may be correct because of an Arcade syntax requirement.
How would the code be written to include the IsEmpty syntax and I take it that the code would be inserted after line 23?
You already are checking for null a couple lines later in the same way.
// construct the update instructions
var update = {"globalID": parent_id, "attributes": {}}
if (date_field != null) {
update.attributes[date_field] = $feature.InspectionDate
}