Attribute Rule to pass a value from parent to child

169
13
Jump to solution
12-08-2021 07:59 AM
dcamara924
New Contributor II

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!

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
Regular Contributor
// 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}}

 


Have a great day!
Johannes

View solution in original post

13 Replies
JoeBorgione
MVP Esteemed Contributor

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.

That should just about do it....
dcamara924
New Contributor II

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.

0 Kudos
JoeBorgione
MVP Esteemed Contributor

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.

 

JoeBorgione_0-1638990286653.png

 

That should just about do it....
0 Kudos
JohannesLindner
Regular Contributor
// 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}}

 


Have a great day!
Johannes
dcamara924
New Contributor II

Thanks Johannes! This helped me develop what I was looking for. Simple and straightforward. Much appreciated.

0 Kudos
PetronellaHauptmann1
New Contributor II

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

0 Kudos
JohannesLindner
Regular Contributor

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

Have a great day!
Johannes
0 Kudos
PetronellaHauptmann1
New Contributor II

Thanks Johannes, but sadly it doesn't work.

PetronellaHauptmann1_0-1641979217968.png

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.

0 Kudos
JohannesLindner
Regular Contributor
  • Try using the simple name of the field (like you did in your code above):
var parent_fs = FeatureSetByRelationshipName($feature, "Matstallen_Rate", ['Namn'])
  • Make sure that "Matstallen_Rate" is actually the name of the relationship class, not the name of the parent feature class!
  • Try using the full name of the relationship class: "DatabaseName.DataOwner.Matstallen_Rate"

Have a great day!
Johannes
0 Kudos