Select to view content in your preferred language

Arcade Calculated Expression - Attribute from related record

1397
4
Jump to solution
07-19-2023 07:31 AM
RiainGarcia
Occasional Contributor

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! 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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)

relationships.png

View solution in original post

4 Replies
KenBuja
MVP Esteemed Contributor

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)

relationships.png

RiainGarcia
Occasional Contributor

Genius! Thank you

0 Kudos
Krocha
by
Regular Contributor

I copied this same script, but it still returns null even if there are related records. 

0 Kudos
marksm_macomb
Frequent Contributor

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?