How to update a parent field when a related child field changes using Arcade?

3404
10
Jump to solution
09-18-2020 10:42 AM
TheodoreRakel
Occasional Contributor

I'm writing an immediate calculation attribute rule using Pro version 2.6.1.  I have a relationship defined between a parent feature and children objects.  Whenever the user changes either the parent or any of its children, I need to update a field on the parent feature.  Is this possible using Arcade and immediate calculation attribute rules?  I've written the rule and it works fine when I change the parent feature, but it doesn't fire when I change the related child objects.  Then I began writing a second rule for the child object, but I realized that I would ultimately be changing something on the parent feature, which I do not think can be done using Arcade and immediate calculation attribute rules.  The rule would also have to execute whenever a new object is related to the parent or an existing object is unrelated from the parent.

0 Kudos
1 Solution

Accepted Solutions
HusseinNasser2
Esri Contributor

Yes this is definitely possible,

Assuming two tables T1, T2 , T1 is related to T2 via field KEY

you will add an attribute rule on T1  and you can have it trigger on update so that it makes an edit to T2 and update the related feature on T1 (find the parent feature by querying T1.KEY = $feature.KEY ..  

Here is a blog detailing this 

Advanced Attribute Rules – Editing features on another class with attribute rules 

You can restrict the attribute rule to execute only if a certain field has been updated by using $originalFeature 

View solution in original post

10 Replies
JosephMarsh
New Contributor II

Hussein NasserMichael Miller‌ Hi Hussein and Mike, Do you know if this is possible?

0 Kudos
JosephMarsh
New Contributor II

Thank you!

0 Kudos
HusseinNasser2
Esri Contributor

Yes this is definitely possible,

Assuming two tables T1, T2 , T1 is related to T2 via field KEY

you will add an attribute rule on T1  and you can have it trigger on update so that it makes an edit to T2 and update the related feature on T1 (find the parent feature by querying T1.KEY = $feature.KEY ..  

Here is a blog detailing this 

Advanced Attribute Rules – Editing features on another class with attribute rules 

You can restrict the attribute rule to execute only if a certain field has been updated by using $originalFeature 

JosephMarsh
New Contributor II

Thank you!

0 Kudos
TheodoreRakel
Occasional Contributor

Is it possible to know when a related child object has been unrelated from its parent feature?  I'm using $originalFeature and can compare it to $feature to determine if the child was related to a parent and now is been unrelated.  I wrote a Calculation Rule and set the trigger to Update, but the code I wrote doesn't seem to get executed when I remove a child from a relationship in Pro.  I want to set a field on the parent to null in the case of a child becoming unrelated.  Is removing a child from a relationship not considered an Update?

0 Kudos
HusseinNasser2
Esri Contributor

Yes it is possible, 

create a constraint attribute rule on an update trigger and use $feature to query the related table to see if object still exist in the related table and block the edit if the object has been severed from the parent. 

if you found a row that means the object still related, if you didn't that mean the object has just been recently removed and as a result you can block that by return false.

0 Kudos
TheodoreRakel
Occasional Contributor

I do not want to prevent the child from being unrelated to the parent.  I want a field on the parent to be set to null if the user chooses to unrelate a child from the parent as shown in the screen shot below.  Will a constraint rule allow me to do this? 

0 Kudos
HusseinNasser2
Esri Contributor

Yup you can do this with a calculation rule easily. 

constrain prevent edits, calculation changes the state of the row.

0 Kudos