I have a polygon hosted feature layer along with a related table in ArcGIS Online. The layer and table are related via GlobalID and ParentGuid.
I'm attempted to add a calculated expression through forms on map viewer, and what i'm trying to achieve is that when a related record is added, the surveyor must add a "Status" on the related record. I'd then like the calculated expression to be against the "Status" field on the feature layer, and when the related record is added, the following expression will update the "Status" on the feature layer of the "Status" on the related record.
My expression is successfully executing but is always returning null, which I assume means it can't find a match between GlobalID and ParentGuid, but a quick check on the table reveals there are matches and this can also be proven by clicking on the popup to reveal the related records.
var relatedRecords = FeatureSetByName($datastore, 'Test_Log', ['Status'], false);
var parentId = $feature.GlobalID;
for (var record in relatedRecords) {
if (record.ParentGuid == parentId) {
return record.Status;
}
}
return null;
Any help would be great!
Solved! Go to Solution.
You can use the FeatureSetByRelationshipName function to return the related records for a feature.
var related = FeatureSetByRelationshipName($feature, 'your relationship name');
if (Count(related) > 0) {
var record = First(related);
return record.Status;
}
You'll need to know the Relationship name, which is found in the feature layer's service page (like this one)
You can use the FeatureSetByRelationshipName function to return the related records for a feature.
var related = FeatureSetByRelationshipName($feature, 'your relationship name');
if (Count(related) > 0) {
var record = First(related);
return record.Status;
}
You'll need to know the Relationship name, which is found in the feature layer's service page (like this one)
Genius! Thank you
I copied this same script, but it still returns null even if there are related records.
Hi @RiainGarcia,
I think I'm trying to do something similar to you, but I'm not quite following your process. Is your calculated expression being applied to a field in your parent feature or the related table? If it is on the parent feature, how is it being triggered when a related record is added?