View fields from related table in popup and concatenate

410
3
12-31-2023 11:09 PM
Damian
by
New Contributor III

Dear AGOL Communitity

I'm trying to write an expression to view two text fields from a related table in a pop up in a WebMap. I also want to concatenate those two fields so they appear a custom field. I am a total novice at writing Arcade expressions. Hoping someone can help.

My primary feature dataset is called 'Distributions'

My related table is called 'Taxa'

The two fields I want to concatenate from my Taxa table are called 'Genus' and 'Species'

Hoping someone can help

Regards, Damian

0 Kudos
3 Replies
BertKraan1
Occasional Contributor III

Learning Arcade can be a steep learning curve. I use this https://developers.arcgis.com/arcade/function-reference/ a lot. 

Succes!

0 Kudos
EmilyGeo
Esri Contributor

Hi @Damian

To help you get started, here is a link to a Story map on writing some basic expressions in Arcade: What is Arcade and why use it

To fetch the attributes from a related table, here is a link to a blog post that goes over some common expressions. See section 2: Fetch an attribute from a related record. The blog has sample code to help you get started. You can copy and paste the code, then change the name(s) of the dataset/relationship/field(s) to match your dataset. 

However, you can display attributes from related records in pop-ups without the use of Arcade. 

When configuring your popup, click +Add Content then Related Records and select your related table. 

Hope that helps! 

Damian
by
New Contributor III

Ok, after many, many iterations (and a little help from Chat GTP) , I finally managed to crack it. For the benefit of other newbs like me, here is my Arcade code...

var relatedRecords = FeatureSetByRelationshipName($feature, 'Taxa');
var displayString = '';

// Loop through related records
for (var record in relatedRecords) {
    displayString += record['Genus'] +' '+ record['species'];
}

// Display the generated string in the popup
return displayString;

 Cheers, Damian