Attribute Rule Delete Trigger to Update Another Feature

1830
5
12-11-2019 07:16 AM
MichaelBrown4
New Contributor III

Hello,

I've been really enjoying attribute rules and trying them out on a few workflows, mostly with success.  One workflow I have though is not yielding the results I would want/expect.

I have two polygon feature classes, Campus and a Site, that each have an Insert/Update set of triggers that will pass the Campus ID value to the Site feature if they intersect.  If a new Site is created or updated (moved) within a Campus, it will get that Campus's ID value.  If a Campus is created or updated (moved) to intersect an existing Site feature, the Campus ID will be set on that Site feature.

I have a Delete trigger on the Campus whose intent is to set the Campus ID to Null for all Site's that have that deleted record's Campus ID.  While I think the logic for this could be better (it would be great to somehow take the Delete trigger from Campus and then trigger the Site feature to check for intersects again...can you do this?), it seems like it should work.  What I am finding is the Arcade Expression has an Edit/Update to the Site feature to change the Campus ID field value to Null and that in turn is triggering the trigger I noted above where the Site get's the intersecting Campus's, Campus ID value and this never gets set to Null.  It seems the actual delete of the record is happening after the Edit/Update and the Update trigger that runs on Site, so there is still a valid intersect with the Campus record I am deleting.

Here is the Delete trigger on Campus

var fsSitesFilter = filter(fsSites , "Campus_ID = @campusId")
if (count(fsSitesFilter ) == 0) return $feature.ID;

var updates = []

var i = 0
for (var site in fsSitesFilter) {
   updates[i++] = {
      'globalid': site.GlobalID,
      'attributes': {"Campus_ID": null}
   }
}

return {
   'result': null,
   'edit': [
      {'className': 'sde_blah.Site',
      'updates': updates
      }
   ]
}

Here is the Insert/Update trigger on Site

var fsCampus = FeatureSetByName($datastore, "sde_blah.Campus", ["ID"], true)
var fsSite = Intersects(fsCampus, Geometry($feature))
var campus = First (fsSite)

var campus_id = ""
if (campus == null)
   return null
else
   campus_id = campus.ID

return campus_id;

0 Kudos
5 Replies
JohannesLindner
MVP Frequent Contributor

No idea if and how you could do that with attribute rules (getting into them myself right now), but you could create a relationship class linking Campus.ID to Site.CampusID.

That way, if you delete a Campus feature, all corresponding Site features' CampusID is set to NULL.


Have a great day!
Johannes
MichaelBrown4
New Contributor III

That's a good idea, that should work well.  I'll give that a try.  Thanks for that!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Michael.Brown31@jacobs.com_Jacobs ,

Not sure if this helps, but when you delete a feature you may need to use the $originalfeature... See: $originalFeature – New Attribute Rules Arcade Global 

0 Kudos
MichaelBrown4
New Contributor III

Thanks Xander Bakker‌, I had seen that, but not had a chance to try.  My preference would be to avoid the relationship class because there is a complicated web of how different feature classes can overlap and relate to each other.  I'll give this a try.

0 Kudos
Boomer1187
New Contributor II

Hi @MichaelBrown4 , curious if you found a resolution to this one as I'm having trouble with a similar issue.

My project has attribute rules that are triggered by insert/delete with two polygon classes with different projects. When they intersect one another, there is a project_number attrbute that gets updated in one of the datasets whenever a new polygon is created that intersects the other polygon. I am having trouble with having the project_number value be removed or set to null when the same intersecting polygon is deleted.

Did you have luck with the $originalFeature arcade global?

0 Kudos