Related Table changing attributes of a Layer

11-29-2023 12:08 PM
New Contributor

I am trying to see if I can change an attribute in a field for a layer through its related table. We have inspections on Hydrants for example. I want to see if I can change a field in the native hydrant layer by changing something in the Related Table inspection form. I have been steered towards investigating attribute rules to accomplish this, but just a little confused on if this is possible or not. 

Thanks for any help out there!

0 Kudos
2 Replies
MVP Regular Contributor

Happy to help you with this as I had struggled with this and with the help of others on this forum learned that it's absolutely possible! Here's the code example:

// Calculation Attribute Rule on Inspections
// field: leave empty
// Triggers: Insert (and Update, if you want the rule to trigger upon editing an already existing form. Kind of up to your workflow.)
// Exclude from application evaluation!

// get the related asset
var asset_id = $feature.GUID
var assets = FeatureSetByName($datastore, "parent_feature")
var asset = First(Filter(assets, "GlobalID = @asset_id"))
// if there is no related asset, end expression
if(asset == null) { return }
// else populate attribute with the edit
return {
    edit: [{
        className: "parent_feature",
        updates: [{
            objectID: asset.OBJECTID,
            attributes: {
                Status: $feature.Struct,
                LastInspDate: $feature.InspDate
		// add additional attributes as necessary

So you add this attribute rule to the form table itself, not to the parent feature class. In this case, my parent feature is "parent_feature". You can get your correct parent feature name if you use the Arcade helper in the attribute rule and search for FeatureSetByName. 

Basically, you use the GUID of your child feature class and then run a filter statement to match up the GlobalID of the parent to the GUID of the child. Then, down in the return statement, you enter in the attributes of the parent you want to edit based on the values from the newly created (or edited) child record. In the example above, the attribute "Struct" from the related record will be populated into "Status" from the parent record, etc.

0 Kudos
Occasional Contributor III

It is possible. We are currently doing the same thing and I have created an attribute rule that will not only insert a record into a related table whenever there is a new inspection on a hydrant but also update the same record if something in the record changes. Right now, the rule is set to insert/update from the hydrant feature service to the related table. However, it is possible to create attribute rules where both features can update one another.

0 Kudos