My asset layers, like utilities or leases, etc. have the same fields in them over and over to denote buildings related to the asset. The fields represent the building names and I am storing a boolean value in the fields (y/n). If an asset is associated with a building I place a 'y'. This is probably not ideal, but it is how it is being done. I want to show a list of buildings in the pop up so I put together this functional arcade script. Sharing it here for others that might find it helpful.
//Create list of fields that store Y/N for if a building is associated
var building_flds = ['Str_100', 'Str_101', 'Str_102']; //If new building fields are added, then add them to this list
var buildings = [];
//If a building has been marked as Yes, then add the alias to a concatenated list for display in the popup
for (var i in building_flds){
if ($feature[building_flds[i]] == 'Y') {
var aArray = Schema($layer)["fields"];
for(var j in aArray) {
var dict = aArray[j];
if (dict['name'] == building_flds[i]){
push(buildings,dict['alias']);
};
};
}
}
iif (Count(buildings)==0,push(buildings,'<em>None</em>'),buildings)
var Expression2 = concatenate(buildings, ", ")
I had to do something similar, where I had many fields, each showing the count of a different species. Each species field had a name beginning with "MAX_", with the scientific name of the species as the field alias. I only listed the species that had a count greater than 0.
This might be helpful in making your code more efficient, since you don't have to modify it for new building fields, as long as they hold to the same naming scheme. I returned a bulleted list, with the commented out lines showing how to return a comma-separated list with an "and" before the last item.
var theSchema = Schema($feature);
var fields = theSchema['fields'];
var species = [];
for (var i in fields) {
if (Find('MAX', fields[i]['name']) > -1 && $feature[fields[i]['name']] == 1) {
Push(species,fields[i]['alias']);
}
}
//if (Count(species) == 1) return species[0];
//if (Count(species) == 2) return Concatenate(species, ' and ');
//return `${Concatenate(Slice(species, 0, count(species) - 1), ', ')}, and ${species[Count(species) - 1]}`
return `• ${Concatenate(species,'\n• ')}`;
This expression was used to make this popup