Attribute Rule to pass a value from parent to child

5492
20
Jump to solution
12-08-2021 07:59 AM
dcamara924
New Contributor II

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
20 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
New Contributor II

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
New Contributor II

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
New Contributor II

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
ErikBell1
New Contributor II

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
Occasional Contributor III

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
JohannesLindner
MVP Frequent Contributor

It looks as if the rule doesn't find the parent feature and aborts in line 6. You could test that theory by returning a default value if that happens. 

Also, you're getting the related features in line 1 and then filter these features in lines 2&3. I used FeaturesetByName in my example and had to use the filter to get the related features. You use FeaturesetByRelationshipName, so the parent_fs already contains only the related features, the filter doesn't do anything.

var parent_fs = FeatureSetByRelationshipName($feature, "SAN_Manhole_To_SAN_Manhole_Inspection");

var manhole = First(parent_fs);
if (manhole == null) {return {"result": {"attributes": {"LOCATIONDESCRIPTION": "No parent feature found!"}}}};

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

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

 


Have a great day!
Johannes