Select to view content in your preferred language

Configuring pop-up expression to group by common feature

516
3
02-03-2022 01:17 PM
Labels (1)
cpenling
New Contributor III

I've created an arcade expression that pulls species data from a related table. Instead of having Lower_Taxon as one of the listed attributes, I'm wondering if I can sort or group the list by it. 

This is my current code:

var relatedrecords = FeatureSetByRelationshipName($feature,"Provincially_Tracked_Species_Detail_CRCA");
var popupString = ""
for (var f in relatedrecords){
    popupString += Text(f.Com_Name) + TextFormatting.NewLine +
    
        "Scientific Name: " +
        DefaultValue(f.Sci_Name, 'no data') + TextFormatting.NewLine +
        
        "Taxon: " +
        DefaultValue(f.Lower_Taxon, 'no data') + TextFormatting.NewLine +
        
        "SARO Status: " +
        DefaultValue(f.SARO_Status, 'no data') + TextFormatting.NewLine +
        TextFormatting.NewLine
}
return popupString

This is what the results look like now: 

Pop-up Results.JPG

And this is what I'm hoping for them to look: 

Pop-up Goal.JPG

Please let me know if you have any suggestions on how to accomplish this. 

0 Kudos
3 Replies
jcarlson
MVP Esteemed Contributor

Grouping by an attribute could be a bit tricky, but doable. For the sake of having a concise expression, you may wish to take advantage of custom functions.

function addToString(string, feat){
    string += `${Text(f.Com_Name)}
    Scientific Name: ${DefaultValue(f.Sci_Name, 'no data')}
    SARO Status: ${DefaultValue(f.SARO_Status, 'no data')}

    `
    return string
}

var popupString = ''

var relatedrecords = FeatureSetByRelationshipName($feature,"Provincially_Tracked_Species_Detail_CRCA");

// return set of distinct taxon values
var taxons = Distinct(relatedrecords('Lower_Taxon'))

for (var t in taxons){
    
    var taxon_name = t.Lower_Taxon
    
    // Add taxon heading to popup string
    popupString += taxon_name + TextFormatting.NewLine
    
    // Filter related records for matching taxon name
    var taxon_records = Filter(relatedrecords, 'Lower_Taxon = @taxon_name')
    
    // Add filtered record details to output string
    for (var f in taxon_records){
        popupString = addToString(popupString, f)
    }
}
- Josh Carlson
Kendall County GIS
0 Kudos
cpenling
New Contributor III

Unfortunately, this isn't working for me. It doesn't return anything. 

0 Kudos
Rice_GIS
New Contributor III

Did you ever find out how to do this?

 

0 Kudos