Hello. I'm attempting to pass a value from a parent feature to a related table using an Attribute Rule. The idea being that when a new related record is created it automatically populates this field based on its corresponding parent value. This seems like it should be easy to do but the arcade expression is proving challenging for my beginner level of arcade experience. The fields are both called "GPMDesign" and are both "Long" field types. I'm running ArcGIS Pro 2.7.1 and Enterprise 10.8.1. Thank you!
Solved! Go to Solution.
// calculation attribute rule on child
// field: if you want to get only one field from the parent, then chose
// that field. if you want to get multiple fields, leave empty
// triggers: Insert(, update)
// load the related parent features using one of these methods
// if you have a relationship class between parent and child:
var parent_fs = FeatureSetByRelationshipName($feature, "RelationshipName")
// if not
var parent_fs = FeatureSetByName($datastore, "NameOfParentFC")
var key = $feature.ForeignKeyField
parent_fs = Filter(parent_fs, "PrimaryKeyField = @key")
// return nothing if no parent feature was found
var parent = First(parent_fs)
if(parent == null) { return }
// if you want to return only one field:
return parent.Field
// if you want to return multiple fields:
var att = {
"Field1": parent.Field1,
"Field2": parent.Field2
}
return {"result": {"attributes": att}}
Take a look at the ESRI Address Data Management Solution; it has similar rules written between address points and related site address points. There is an aprx you can download that has sample data and the rules are applied there.
Thanks Joe. I think I found what you were referring to in one of the web map's pop up configurations. Neither the tables or feature layers had actual Attribute Rules on them that I could see. It still seems way more complicated than it should though. I'll keep tinkering with the FeatureSet functions.
The rules are fairly complicated, but I can find them by Right Clicking on Address Points in the table of contents, selecting Design and then Attribute Rules. In the solution, the work flow has the user drop an Address Point on a street centerline and through a relationship class a Site Address Point is created.
// calculation attribute rule on child
// field: if you want to get only one field from the parent, then chose
// that field. if you want to get multiple fields, leave empty
// triggers: Insert(, update)
// load the related parent features using one of these methods
// if you have a relationship class between parent and child:
var parent_fs = FeatureSetByRelationshipName($feature, "RelationshipName")
// if not
var parent_fs = FeatureSetByName($datastore, "NameOfParentFC")
var key = $feature.ForeignKeyField
parent_fs = Filter(parent_fs, "PrimaryKeyField = @key")
// return nothing if no parent feature was found
var parent = First(parent_fs)
if(parent == null) { return }
// if you want to return only one field:
return parent.Field
// if you want to return multiple fields:
var att = {
"Field1": parent.Field1,
"Field2": parent.Field2
}
return {"result": {"attributes": att}}
Thanks Johannes! This helped me develop what I was looking for. Simple and straightforward. Much appreciated.
Hi!
I'm trying this and can't make it work somehow.
My feature class, relationship class and table are stored in an sde database. I have a relationship class between parent and child. My script looks like this. It validates but when I create a new feature the field in which the attriute rule is applied won't update.
// calculation attribute rule on child
// field: if you want to get only one field from the parent, then chose
// that field. if you want to get multiple fields, leave empty
// triggers: Insert(, update)
// load the related parent features using one of these methods
// if you have a relationship class between parent and child:
var parent_fs = FeatureSetByRelationshipName($feature, "Matstallen_Rate", ['Namn'])
// return nothing if no parent feature was found
var parent = First(parent_fs)
if (parent == null) { return }
// if you want to return only one field:
return parent
Super thankful for your help
Your problem is in the last line: You try to return the whole parent feature. Even if you only load one field (Namn), the feature still holds other information, such as geometry. You have to specify what field you want to return:
return parent.Namn
Thanks Johannes, but sadly it doesn't work.
This error occurs. Any suggestions to what might be the issue?
I'm new to Arcade, and I've been trying to find the solution for days now, but I'm stuck.
var parent_fs = FeatureSetByRelationshipName($feature, "Matstallen_Rate", ['Namn'])