When Updating Child Table Fields from Parent FC Fields, How to Update ALL Related Records

155
5
Jump to solution
2 weeks ago
ChristopherBowering
Occasional Contributor II

I have an attribute rule that runs on a field within a point feature class.  The value of said field is passed to a desired related table field when said parent field is populated or updated.  There is a 1:M relationship class using the GlobalID of the feature class and GUID of the table.  As it stands, only the FIRST table record receives the updated value if there are multiple records associated with a single feature.  This is due to the Arcade code using the 'First' FeatureSet function.  I borrowed and adjusted this code to get me this far but I don't know how to further adjust it so ALL related records receive the same update from the parent field.  Any help would be great!

 

if($originalfeature.Size == $feature.Size) { return }

var TEST = First(FeatureSetByRelationshipName($feature, "OCGIS.DPW_TESTING_REL"))
if(TEST == null) { return }

return {
  "edit": [
    {
      "className": "OCGIS.DPW_TESTING_Table",
      "updates": [
        {"globalID": TEST.globalid, "attributes": {"Size": $feature.Size}}
      ]
    }
  ]
}

 

 

0 Kudos
1 Solution

Accepted Solutions
MikeMillerGIS
Esri Frequent Contributor

Just need to loop over the FeatureSet and build a list of return values

if ($originalfeature.Size == $feature.Size) {
    return
}

var fs = FeatureSetByRelationshipName($feature, "OCGIS.DPW_TESTING_REL");

var updates = [];
for (var feat in fs) {
    Push(updates, {
        "globalID": feat.globalid,
        "attributes": {
            "Size": $feature.Size
        }
    });
}

return {
    "edit": [
        {
            "className": "OCGIS.DPW_TESTING_Table",
            "updates": updates
        }
    ]
}

View solution in original post

0 Kudos
5 Replies
MikeMillerGIS
Esri Frequent Contributor

Just need to loop over the FeatureSet and build a list of return values

if ($originalfeature.Size == $feature.Size) {
    return
}

var fs = FeatureSetByRelationshipName($feature, "OCGIS.DPW_TESTING_REL");

var updates = [];
for (var feat in fs) {
    Push(updates, {
        "globalID": feat.globalid,
        "attributes": {
            "Size": $feature.Size
        }
    });
}

return {
    "edit": [
        {
            "className": "OCGIS.DPW_TESTING_Table",
            "updates": updates
        }
    ]
}
0 Kudos
ChristopherBowering
Occasional Contributor II

Hi there @MikeMillerGIS .  That did the trick!  THANK YOU!

0 Kudos
ChristopherBowering
Occasional Contributor II

Hi again @MikeMillerGIS .  I am running into an infinite loop issue ("the evaluation of attribute rules is cyclic or exceeds maximum cascading level.") when using the above rule in conjunction with another rule you helped me out with.

When Multiple Child Records Exist, How to Carry Over Field Value of MOST RECENT Record to Parent Fie... 

If I disable the rule which carries over children values to parent fields (set on child table), this initial update all related records rule (set on parent fc) works fine.  When they're both enabled though, the initial rule throws the error when I update the parent field.

Note: The two rules do not deal with any of the same fields.  

Do you know how the rule within this thread could be adjusted to prevent the looping/error situation?

Thanks!

0 Kudos
MikeMillerGIS
Esri Frequent Contributor
I am not sure, hard to troubleshoot with a dataset to see what is going on.
0 Kudos
ChristopherBowering
Occasional Contributor II

From what I've been reading (and trying to understand..) this isn't too unusual of a problem.  It doesn't stem from the dataset.  I've seen it corrected by changing up the attribute rule script: Something like this example.   

However, the examples of it being corrected are more complicated than mine so I'm not exactly sure how to apply a fix to my situation.  The key part for me is the understanding of it which hurts my head sometimes!

0 Kudos