Select to view content in your preferred language

Attribute Rule to pass a value from parent to child

7518
21
Jump to solution
12-08-2021 07:59 AM
dcamara924
Emerging Contributor

Hello. I'm attempting to pass a value from a parent feature to a related table using an Attribute Rule. The idea being that when a new related record is created it automatically populates this field based on its corresponding parent value. This seems like it should be easy to do but the arcade expression is proving challenging for my beginner level of arcade experience. The fields are both called "GPMDesign" and are both "Long" field types.  I'm running ArcGIS Pro 2.7.1 and Enterprise 10.8.1. Thank you!

0 Kudos
21 Replies
JohannesLindner
MVP Frequent Contributor

Your problem is in the last line: You try to return the whole parent feature. Even if you only load one field (Namn), the feature still holds other information, such as geometry. You have to specify what field you want to return:

return parent.Namn

Have a great day!
Johannes
0 Kudos
PetronellaHauptmann1
Emerging Contributor

Thanks Johannes, but sadly it doesn't work.

PetronellaHauptmann1_0-1641979217968.png

This error occurs. Any suggestions to what might be the issue? 

I'm new to Arcade, and I've been trying to find the solution for days now, but I'm stuck.

0 Kudos
JohannesLindner
MVP Frequent Contributor
  • Try using the simple name of the field (like you did in your code above):
var parent_fs = FeatureSetByRelationshipName($feature, "Matstallen_Rate", ['Namn'])
  • Make sure that "Matstallen_Rate" is actually the name of the relationship class, not the name of the parent feature class!
  • Try using the full name of the relationship class: "DatabaseName.DataOwner.Matstallen_Rate"

Have a great day!
Johannes
0 Kudos
PetronellaHauptmann1
Emerging Contributor

Still empty 😞

PetronellaHauptmann1_0-1641983682581.png

I am super greatful for all your valuable help. In my head this seemed like a really basic task, but I can't make it work.

0 Kudos
JohannesLindner
MVP Frequent Contributor

Have you actually triggered the rule? Eg updated the feature? Try putting in a value into Kommentar or Namn


Have a great day!
Johannes
0 Kudos
PetronellaHauptmann1
Emerging Contributor

Now I feel ashamed. I've only tried to add new rates, not updating existing ones. The rule works.

Thank you so much for your patience and your help!

All the best!

0 Kudos
JohannesLindner
MVP Frequent Contributor

No reason to be ashamed, we've all had our share of facepalm moments... Glad it works 🙂

If you want to trigger the rule for all features, use CalculateField on Namn and just put some random value in it.


Have a great day!
Johannes
0 Kudos
MHeadley
Emerging Contributor

I've spent the last several hours with the same problem - I appreciate all the feedback, you've been generous with your time.  So now my rule works too!!  BUT only after I update the record???  Why doesn't on "Insert"  trigger the rule as the record is created... our workflow is for inspection records - you don't typically ever go back and "Update" them - so really the rule is not functioning as hoped.  I will be continuing to figure out what I'm missing to get the rule to work as the new record is created.  Thanks.

0 Kudos
ErikBell1
Emerging Contributor

Johannes,

Is there a way for this to automatically trigger without trying to put a value in the field? I am trying to update field in child feature when parent feature is changed/updated. With this script, I have to delete the existing value in the child field for it to change to value present in parent field.

 

Thanks,

Erik

0 Kudos
BrianBulla
Honored Contributor

Hi @JohannesLindner .  So I'm using the code below which kind of works for updating multiple fields in the child object based on the matching field in the parent, but it only works when I update the child, not when the child is first created.  (I do have both the update and insert triggers checked).

Is there something I am missing in order to get it to work when the records is first created??

var parent_fs = FeatureSetByRelationshipName($feature, "SAN_Manhole_To_SAN_Manhole_Inspection");
var key = $feature.FACILITYID;
parent_fs = Filter(parent_fs, "FACILITYID = @key");

var manhole = First(parent_fs);
if (manhole == null) {return};

// get the manhole feature
//var manholes = FeaturesetByName($datastore, 'SAN_Manhole', ['LOCATIONDESCRIPTION', 'SETTLEMENTAREA', 'LOCALMUNICIPALITY', 'DEPOTAREA'], false);
//var facility_id = $feature.FACILITYID;

//var manhole = First(Filter(manholes, 'FACILITYID = @facility_id'));
//if (manhole == null) {return};

var atts = 
{
    "LOCATIONDESCRIPTION": manhole.LOCATIONDESCRIPTION,
    "SETTLEMENTAREA": manhole.SETTLEMENTAREA,
    "LOCALMUNICIPALITY": manhole.LOCALMUNICIPALITY,
    "DEPOTAREA": manhole.DEPOTAREA
};

return {"result": {"attributes": atts}};


0 Kudos