Select to view content in your preferred language

Update parent table from child table in case of Delete trigger

1165
11
08-29-2023 06:24 AM
CarlosK
Emerging Contributor

 

Hi,

I have a use case where I have created a constraint in Delete trigger on ChildTable whether to allow that delete. I also have to update one column of the ParentTable from that same Delete trigger. But thats not happening.

I have multiple conditions for that calculation rule but to avoid confusion I wrote it in a simple way where I am updating the ParentTable's column "Field" on deleting ChildTable row.

return {
"edit": [{
"className": "ParentTable",
"updates": [{
"GlobalID": $feature.ParentTableId,
"Field": 1
}]
}]
}

On delete no error is coming but value of Field in ParentTable is also not updating to 1 when deleting ChildTable's row. Also ChildTable's constraint to delete row is working fine but the above attribute rule is not working

@HusseinNasser2 

Tags (1)
0 Kudos
11 Replies
HusseinNasser2
Esri Contributor

Hey Carlos

 

Do you know version of Pro are you using for this (and is this filegdb or mobilegdb?)

Is this a relationship? or something you maintain manually 

 

if it is relationship we have fixed few bugs with attribute rules eventing and patched them to 2.9.10/3.0.6 and 3.1.3 make sure you are using those.

I'm attaching a sample for insert/update and delete. This is a pole feature that is related to an inspection table. (one pole has many inspections), every time you add an inspection record the count of inspections (a field on the pole) gets updated. if you delete it gets updated accordingly, 

this only work with the fixes in the patches mentioned. 

 

0 Kudos
CarlosK
Emerging Contributor

I am right now using the latest Pro version.We are using enterprise geodatabase(sql). And this is a relationship.

@HusseinNasser2 

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Take a look at this, it does not rely on a relationship, but a child/parent key - https://github.com/Esri/arcade-expressions/blob/master/attribute_rule_calculation/UpdateParentFeatur...

 

0 Kudos
JamesBooth
Regular Contributor

Any chance that calculation can be shared again? Link doesn't seem to be active. Perhaps not relevant to ArcGIS Pro 3.3 or greater?

0 Kudos
BrettLessner
Frequent Contributor

Mike,

I've been working with the Update Related template. It only seems to be working with the update trigger. I've checked the Insert and Delete triggers, but the related table doesn't change. Any thoughts on what I may have done wrong?

Running Pro 3.5.2

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Are you using the Add Related Feature in pro?  There is an order of events that the insert rule finishes before related feature gets the parent guid.  So the relationship does not exist during the insert event.

0 Kudos
BrettLessner
Frequent Contributor

Mike,

I've been testing the attribute rules by selecting features and using "Add Selected Feature to Relationship", "Remove All From Relationship", and deleting features. At this point, the Insert trigger seems irrelevant as the relationship is created after features are already created. That leaves Update and Delete Triggers.

To provide context, I have a point feature class (one) that is related to a line feature class (many). The goal is to sum the lengths of lines related to a point. 

My solution so far is two rules:
1) When line feature is updated, calculate and push sum to related point.
2) When feature is deleted, calculate and push sum - deleted feature length to related point.

I'm not sure if this is most efficient, but it's working. My only issue now is when I remove a line from the relationship or change what point it's related to. When I make those changes, the previously related point does not get updated.  

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Could you use $OriginalFeature and if the parent key changes, query the old parent feature and update it?

0 Kudos