Attribute Rule - Related Table - Foreign Key null return

644
2
Jump to solution
01-14-2022 07:17 AM
DavidFotheringham1
Occasional Contributor

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

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

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}}

Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

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}}

Have a great day!
Johannes
DavidFotheringham1
Occasional Contributor

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

0 Kudos