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!
Solved! Go to Solution.
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
}]
}
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
}]
}
@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!
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..
Genius! Thank you again for your assistance as well as your tutorials on YouTube. All of this has been extremely helpful