Fetch an attribute from a related record

278
1
09-19-2023 06:39 AM
Sarah-CodyKnight
New Contributor II

Hi there,

I have a point layer and three related tables in a collection map on Field Maps. In the form of one of the tables, I want a text field to auto fill based on what's in a text fields in the point layer. I'm brand new to using expressions in Field Maps, and so tried adapting the following from one of Esri's posted examples on Common calculated expressions, but get an error in Field Maps saying "Failed to calculate". Any help would be great. Thanks.

var plants_sept_source = FeatureSetByRelationshipName($feature, 'Sept_Measure_Butternut_data_sheet', ['current_plant_source'], true)
if (!IsEmpty(plants_sept_source)) {
return plants_sept_source['current_plant_source']
} else {
return null
}
 
I've also tried the following, with no luck.
var related_features = FeatureSetByRelationshipName($feature, "Sept_Measure_Butternut_data_sheet", ["current_plant_source"], false)
var related_feature = First(related_features)

if(related_feature == null) {
    return null  
}

return related_feature.current_plant_source
 
0 Kudos
1 Reply
DougBrowning
MVP Esteemed Contributor

I am not sure you will get null at all.  What I do is use count like this.

var related_features = FeatureSetByRelationshipName($feature, "Sept_Measure_Butternut_data_sheet", ["current_plant_source"], false)

if count(related_features) == 0 {

     return "none found"

}

else {

return First(related_features).current_plant_source

}

Note syntax is not perfect but I hope you get the idea.

0 Kudos