Select to view content in your preferred language

Adding features to related tables

1647
4
Jump to solution
10-05-2023 03:25 AM
Labels (3)
JamesTurner2
Regular Contributor

I have a table that contains organization names and a feature class that contains features that belong to the organizations. This is a 1-M relationship, organizations can be related to many features, but the features only relate to one organization. The primary key would be the organization's name. The table contains a GUID for each organization.

I would like the relationship class set up so that when I add a new feature, and enter the organizations name, the org's GUID populates another field in the feature class. Is there a way to set up the relationship class so that this happens automatically? It seems similar to a composite relationship. I don't have a solid understanding of how related tables work, so I'm not sure if this is possible, or if I need to take another approach. I think the other way to accomplish my goal would be to use an arcade expression in a calculation attribute rule to look up the organizations GUID in the table and then write it to the feature class field. 

All data is stored in an enterprise geodatabase

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

You can use an attribute rule for this, have it execute when features are added or edited in the feature class. There are lots of examples in this repo, too: https://github.com/Esri/arcade-expressions/tree/master/attribute_rule_calculation

It would look something like this:

var org = $feature.org_name

var org_fs = FeatureSetByRelationshipName(
  $feature,
  'organizations_features_relationship_name',
  ['guid_field', 'org_name'],
  false
)

matching_org = First(org_fs)

return matching_org['guid_field']

A further refinement would be to check if the original feature and the edited feature have the same value for the 'org_name' field. If that field isn't changing, there's no reason to execute the rest of the expression.

Also, if you anticipate making edits on the organization table, you can use an attribute rule that will take any edits to the table and pass them down to all related features as well.

- Josh Carlson
Kendall County GIS

View solution in original post

4 Replies
jcarlson
MVP Esteemed Contributor

You can use an attribute rule for this, have it execute when features are added or edited in the feature class. There are lots of examples in this repo, too: https://github.com/Esri/arcade-expressions/tree/master/attribute_rule_calculation

It would look something like this:

var org = $feature.org_name

var org_fs = FeatureSetByRelationshipName(
  $feature,
  'organizations_features_relationship_name',
  ['guid_field', 'org_name'],
  false
)

matching_org = First(org_fs)

return matching_org['guid_field']

A further refinement would be to check if the original feature and the edited feature have the same value for the 'org_name' field. If that field isn't changing, there's no reason to execute the rest of the expression.

Also, if you anticipate making edits on the organization table, you can use an attribute rule that will take any edits to the table and pass them down to all related features as well.

- Josh Carlson
Kendall County GIS
JamesTurner2
Regular Contributor

Just what I needed, thanks @jcarlson!

0 Kudos
JamesTurner2
Regular Contributor

I've got this working, if I wanted to implement the refinement you suggest, does that require another related table as laid out in the LastValue script? Or is there a simpler way to execute this?

0 Kudos
jcarlson
MVP Esteemed Contributor

No, you just have to reference the originalFeature object.

var orig_name = $originalFeature.org_name
var org = $feature.org_name

// see if value has changed
if (org == orig_name) {
  // no change, return original value
  return orig_name
} else {
  // change! get GUID from other table
  var org_fs = FeatureSetByRelationshipName(
    $feature,
    'organizations_features_relationship_name',
    ['guid_field', 'org_name'],
    false
  )

  matching_org = First(org_fs)

  return matching_org['guid_field']
}
- Josh Carlson
Kendall County GIS