I have been using attribute rules to fetch information from a related parent table and insert it into a target table, using the FeatureSetByRelationshipName function. This is for an urban forestry work history system.
Here is an example:
var relationship = FeatureSetByRelationshipName($feature, 'RelationshipName', ['TreeSpecies'], false);
// check size of FeatureSet, return null if empty
if(Count(relationship) == 0) { return null }
return First(relationship).TreeSpecies
I'm wondering if it is possible to do this with geometry. Meaning, I want to create a point for work history and add it to a relationship with a particular tree. Then, upon update, it will fetch the geometry of the tree point and insert that into the geometry of the work point, making the work stack directly on top of the tree it's associated with.
Any help is appreciated
To post code:
I'm wondering if it is possible to do this with geometry
Yep. Set the Field to "Shape" and return the other feature's geometry:
// bla bla
return Geometry(First(relationship))
Works like a charm! Much appreciated!
it is as @JohannesLindner suggested,
one thing I would add for performance reason, remove the count query, you are essentially executing two queries, replace it with this
var relationship = FeatureSetByRelationshipName($feature, 'RelationshipName', ['TreeSpecies'], false);
// check size of FeatureSet, return null if empty
//if(Count(relationship) == 0) { return null }
var f = First(relationship);
if (f == null) return null; //if no features exist quit..
return f.TreeSpecies
Thanks for the tip, as well as your many tutorials, they have been a tremendous help! I applied this change to all of my rules now.
This works great in ArcPro but when I republished the feature layer (Portal 10.9.1), I'm running into this error:
" Unable to submit: com.esri.arcgisruntime.ArcGISRuntimeException: Check getCause() for further error information"
This error only occurs when I try to update an existing record (which makes sense because the rules are triggered by "Update"). I disabled the geometry rule for now and everything seems to function correctly.
Here is the rule:
var relationship = FeatureSetByRelationshipName($feature, 'SBCommons.ParksEnvironmental.Trees_TreeWorkOrders', ['Shape'], false);
var f = First(relationship);
if (f == null) return null; //if no features exist quit..
return Geometry(f)
Any thoughts or ideas are appreciated!