Update a parent feature in a relationship when a new child record is inserted

366
0
02-14-2022 11:39 AM
Labels (2)
Yi-ChinFang
New Contributor

Hi all,

I tried to following this post to update last survey date of a parent feature in a relationship when a new child record is inserted using "Add Attribute Rule geoprocessing tool" in ArcGIS Pro. 

Below is the Arcade expression I put in attribute rule. It cannot recognize 'survey_date' field in child record. I cannot figure out how to fix it. Any suggestions on how to fix this are much appreciated!

________________________________________________________________________________________________

// This rule will update an attribute in the parent feature

// Store the parent feature global from the key field in the relationship
var parent_id = $feature.GlobalID;
if (IsEmpty(parent_id))
return parent_id;

// force to upper as the sql is case sensitive
parent_id = Upper(parent_id);

// Using the GDB name, get the parent classes records and Global ID field
var parent_class = FeatureSetByName($datastore, "gsob_trees", ["GlobalID", 'date'], false);
// Filter the parent class for only related features
var parent_records = Filter(parent_class, "GlobalID = @parent_id");

var updates = [];
var i = 0;

// Loop through each feature, create a dict of the Global ID and the new date
for (var row in parent_records)
// updated Date from child record
{
updates[i++] = {
'Global ID': parent_id,
'attributes': {"date": $feature.survey_date}
};
}

// Return the original value in the result parameter, as to not lost the entered value
// Using the edit parameter, return the class and list of updates
return {
'result': parent_id,
'edit': [
{'className': 'ParentLayer',
'updates': updates
}
]
};

0 Kudos
0 Replies