Editing parent attribute from child

887
3
07-01-2021 08:37 AM
DamonBreen
New Contributor III

Hi all,

We have maps that generally all follow the same scheme. There is generally a point class that contains a completion status with 3 options ("Not Completed", "Completed", "Completed and Approved") Each of these point classes represent a real-world feature like a valve or a service etc. We then have inspections in a related table to each of these point classes where the user can answer questions yearly, submit the inspection, and then go back to the parent and mark that it has been "Completed". Every year we reset the completion status to "Not Completed" and it starts over. I'd like to use create an immediate calculation rule that when a new related inspection is created, it updates the completion status field to update it automatically to "Completed". I've used Arcade to create some pop-ups, but this is beyond what I have come up with. 

 

I found this link: https://www.esri.com/arcgis-blog/products/arcgis-pro/data-management/advanced-gdb-attribute-rules-ed..., but it is more about geometry and buffers, and less about just updating a single field. I have some more uses for the attribute rules, but I think this would get me started in the right direction. If someone could help me, I would be so grateful.

 

Thanks for your help!

0 Kudos
3 Replies
DamonBreen
New Contributor III

UPDATE:

I took a stab at writing my own expression to deal with this based on the link provided above, and this is what I've come up with so far, but am getting an error about needing to close a curly lace bracket.


 

//sets the selected feature's guid (key of the relationship) to a variable
var  ForeignKey = $feature.GUID
//find the class to be edited
var fsPoint = FeatureSetByName($datastore, "PointClass")
//filter the class to find the related parent(s)
var bfPoint = filter(fsPoint, "GlobalID = @ForeignKey")
//checks to make sure that there is at least one feature from the parent class
if (count(bfPoint) == 0) return $feature.field;
//grabs the first feature of the parent class
var ParentPoint = first(bfPoint)

return {
//
"result": $feature.field
//keyword for an edit to happen
"edit": [
{
//class to be edited
"className" : "PointClass",
//keyword for what kind of edit to do
"updates" : [
{
//finding the specific feature to be updated
"GlobalID" : ParentPoint.GlobalID,
//what is being updated in that feature
"attributes":
{
//the attribute being edited, and what to change it to
"Completed": "Completed, Not Approved"
}
}
]
}
]
}
​

 


 

0 Kudos
JohannesLindner
MVP Frequent Contributor
// Arcade expects if and for blocks to be enclosed in curly brackets.
// if(condition) {
//  then do this
// }
// for(var f in feature_set) {
// do this
// }

// So your line 8 should look like this:
if(count(bfPoint) == 0) {return $feature.field;}

Have a great day!
Johannes
0 Kudos
DamonBreen
New Contributor III

Johannes, 

I changed my code to match what you put, and enclosed the If statement in curly brackets and tried to compile again, and this time, I got an error that says "Error on line 16. Close curly brace expected", so then I went through my code again, and found where on line 14 I was missing a comma after ""result": $feature.field". I added the comma, and now I get "Error on line 36. Identifier expeced" Which is the last line of the code. I tried a semi-colon after the curly bracket, and that didn't work. Is there something else I'm forgetting?

Not sure what to do with that really.

0 Kudos