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:
And this is what I'm hoping for them to look:
Please let me know if you have any suggestions on how to accomplish this.
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)
}
}
Unfortunately, this isn't working for me. It doesn't return anything.