Hi ESRI Community,
I want to caveat this by stating that I’m a complete rookie to this.
I have a drainage network layer that consists of a feature class with a field that gets populated when an inspection is created. It takes the inspection date attribute from the related table and populates the feature class with that date. The users wanted this so they could quickly look at the features' attributes and see when the last inspection was done. I have this working.
The users now want to modify the feature’s schema to have a field “LastConditionRatingInspectDate” and another field called “LastMaintenanceActivityDate”.
The inspection form has a field “InspectionReason” which gets populated, via a dropdown, with either “Condition Rating” or “Maintenance Activity”.
Based on what the field editor selects in the “InspectionReason” field, I need to have the inspection date populate the “LastConditionRatingInspectDate” if they select “Condition Rating” or the “LastMaintenanceActivityDate” if they select “Maintenance Activity”.
I was thinking an If-then-else would work. If they select “Condition Rating” then the “LastConditionRatingInspectDate” field gets populated with the inspection date, else the “LastMaintenanceActivityDate” would get populated with the inspection date.
Any help on how to make this work would be greatly appreciated!
I’m currently testing using a fgdb in Pro, however, this will be moved to Enterprise for use in web app and Field Maps.
ArcGIS Pro 2.8.8
Arc Enterprise 10.9.1
Here’s the functioning code:
var parent_id = $feature.ParentGUID
if (IsEmpty(parent_id))
return parent_id;
//On the next line, the field LastInspectionDate is the current field which would need to be changed to reflect the new field name
var parent_class = FeatureSetByName($datastore, "CTDOT_Planning_OtherDrainage", ["globalid", 'LastInspectionDate'], false);
var parent_records = Filter(parent_class, "globalid = @parent_id");
return {
'edit': [{
'className': 'CTDOT_Planning_OtherDrainage',
'updates': [{
'globalID': $feature.ParentGUID,
'attributes': {
//On the next line the, the field LastInspectionDate is the current field which would need to be changed to reflect the new field name
'LastInspectionDate': $feature.InspectionDate
}
}]
}]
}
Solved! Go to Solution.
To post code:
You have to make the field that gets updated dependent on the value in InspectionReason. You're correct, you can do this with in if/else. Here, I use When(), which is multiple if/elses chained together, so you can even add more inspection reasons later on.
I also removed the unused loading of the parent table.
var update_field = When(
$feature.InspectionReason == "Condition Rating", "LastConditionRatingInspectDate",
$feature.InspectionReason == "Maintenance Activity", "LastMaintenanceActivityDate",
null // some other inspection reason
)
var parent_id = $feature.ParentGUID
if (IsEmpty(parent_id) || IsEmpty(update_field)) { return parent_id }
var update = {"globalID": parent_id, "attributes": {}}
update.attributes[update_field] = $feature.InspectionDate
return {
'edit': [{
'className': 'CTDOT_Planning_OtherDrainage',
'updates': [update]
}]
}
To post code:
You have to make the field that gets updated dependent on the value in InspectionReason. You're correct, you can do this with in if/else. Here, I use When(), which is multiple if/elses chained together, so you can even add more inspection reasons later on.
I also removed the unused loading of the parent table.
var update_field = When(
$feature.InspectionReason == "Condition Rating", "LastConditionRatingInspectDate",
$feature.InspectionReason == "Maintenance Activity", "LastMaintenanceActivityDate",
null // some other inspection reason
)
var parent_id = $feature.ParentGUID
if (IsEmpty(parent_id) || IsEmpty(update_field)) { return parent_id }
var update = {"globalID": parent_id, "attributes": {}}
update.attributes[update_field] = $feature.InspectionDate
return {
'edit': [{
'className': 'CTDOT_Planning_OtherDrainage',
'updates': [update]
}]
}
Hi Johannes,
Thank you so much for your quick response! It worked perfectly. I'm migrating a number of layers from AGOL to our new Enterprise. In doing so, I'm trying to automate a number of steps. I've completed four, and now with your help I have the fifth one completed. I have two more to do. I'll try to figure them out on my own and if I'm unsuccessful, I'll post to the community.
Again, thank you so much!
Eric
Hi @EricGlover3 ,
In your initial post, you stated that you already have an attribute rule working that populates a feature class field from a related table field when a related table record is created. I'm interested in learning how to do this. Would you be able to share that code?
Thanks!