Select to view content in your preferred language

Attribute Rule to update M:N relationship table using intersect

1238
4
Jump to solution
08-23-2023 12:00 PM
BillMoody
Occasional Contributor

I'm wondering if it would be possible to update a M:N relationship table between a point layer and a polygon layer based on an intersect.  

Example:  I draw a polygon on a map that represents an area that needs to have tree trimming work.  The polygon covers all of the trees (points) that need to be trimmed.  

Upon polygon creation I would like the rule to grab the GlobalID all of the intersecting trees and push them to the relationship table and also grab the GlobalID of the polygon and match that in the corresponding rows of the those tree IDs.  

The reason for this is to make it possible to utilize the many to many relationship within an application like Field Maps, which I don't think can be done out of the box.  

Thanks for any suggestions!

0 Kudos
1 Solution

Accepted Solutions
HusseinNasser2
Esri Contributor

Yes it is possible by returning an edit dictionary against the attributed relationshipclass table, here is a sample filegdb . 

 

 

 

script

 

 

var fs = FeatureSetByName($datastore, "tree");
var fsInt = intersects(fs, $feature);
var payload = [];
var c = 0;
for (var t in fsInt)
{
     payload[c++] = {"attributes": { "treeGUID":  t.globalid, "areaGUID": $feature.globalid} }
} 


return {
     "edit": [{"className": "tree_trimarea",
                "adds": payload
              }]
}

 

View solution in original post

4 Replies
HusseinNasser2
Esri Contributor

Yes it is possible by returning an edit dictionary against the attributed relationshipclass table, here is a sample filegdb . 

 

 

 

script

 

 

var fs = FeatureSetByName($datastore, "tree");
var fsInt = intersects(fs, $feature);
var payload = [];
var c = 0;
for (var t in fsInt)
{
     payload[c++] = {"attributes": { "treeGUID":  t.globalid, "areaGUID": $feature.globalid} }
} 


return {
     "edit": [{"className": "tree_trimarea",
                "adds": payload
              }]
}

 

BillMoody
Occasional Contributor

@HusseinNasser2  you have quickly become my new hero over the last few days.  This works flawlessly!

Quick question:  I am not a coder by any means but I understand the majority of the above.  I am not grasping what "var c" is doing nor the purpose of the array "[c++]".  Could you clarify that variable's purpose as well as what the "++" does to modify it?  Just so I have a better understanding in the future.

 

Much appreciated!

0 Kudos
HusseinNasser2
Esri Contributor

certainly! 

 

c is a variable, and when we say c++ this translate to add 1 to the value of c 

this whole thing is for us to start building a payload 

so essentially each tree gets its own payload 

tree 0 -> payload 0

tree 1-> payload 1 

etc...

and so on..

 

 

 

 

 

BillMoody
Occasional Contributor

Genius!  Thank you again for your assistance as well as your tutorials on YouTube.  All of this has been extremely helpful

0 Kudos