I am attempting to get an attribute from a parent feature class into a child table using attribute rules.
I used this question as a basic. This issue that I have is that the filter does not work because the expression is not finding a value in my parent GUID which is populated by the relationship from the feature class.
Even this code does not work
var gid = $feature.parent_guid
return gid
Every other field in the table returns something. Just not the parent ID (the foreign key in the relationship). This is true if it is a true GUID or just some text (e.g. A)
Any help would be most appreciated. I am using Pro 2.9.1. It also did not work on 2.8
Solved! Go to Solution.
Are you absolutely sure that the field is actually named parent_guid?
If you have a relationship class connecting the two tables, you can also try to use FeatureSetByRelationshipName.
// 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}}
Are you absolutely sure that the field is actually named parent_guid?
If you have a relationship class connecting the two tables, you can also try to use FeatureSetByRelationshipName.
// 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. It definitely was correct. I've tried again on the local geodatabase and it still doesn't work. I will try your method above. I also have a copy on ArcGIS server for use with Field Maps (the intended use anyway) and it works fine through that so I'm not entirely sure the issue but it works for what I need and your script is very clear for future use. Many thanks again
Hi @JohannesLindner ,
I used your script above to successfully carry an attribute from a parent field to a related table field when a new record is created. However, despite the 'update' trigger being checked on within the attribute rule, when I update the pertinent parent field, the corresponding related table field does not update. Is there something additional that needs to be included in the code?
Thanks!