Returning Field Aliases for Specified Fields Using Arcade

73
2
Jump to solution
06-24-2022 06:22 AM
DaveK
by
Occasional Contributor

Hello, 

I'm trying to use Arcade to return the field aliases of fields that have a value of "1" in the data. I have a table of fish species and I would like to return the field alias in the popup anytime there is a value of "1" found in the species record (image of table below). I currently have an Arcade expression that returns all of the field aliases if a "1" is found in the data, but I would like to specify the fields to return. 

Expression I have so far that returns all: 

var features = FeatureSetByName($map, 'Ocean Prime Fishing Grounds', ['*'], false);
var aDict = Schema(features);
var aArray = aDict["fields"];
var output;
for (var i in $feature){
if ($feature[i] == 1) {
for(var j in aArray) {
var dict = aArray[j];
if (dict['name'] == i){
output += dict['alias'] + TextFormatting.NewLine;
}
}
}
}
return output;

Here are the specific fields I would like to return: 

'SUMMFLOUND', 'SEABASSTAU', 'CODPOLLOCK', 'BLUEFISH', 'WEAKFISH', 'STRIPEDBAS', 'TUNA', 'SHARKS', 'BILLFISH', 'BONITOALBA', 'SCUP', 'RED_HAKE', 'LOBSTER'

Example of the data table:

DaveK_0-1656076826394.png

The data I'm using is shared publicly - https://njdep.maps.arcgis.com/home/item.html?id=df7de8c132a749d680ae415b30322fc8

Any help is appreciated. Thanks. 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Honored Contributor

And with some more testing, a shorter way of doing this

 

var fields = ['SUMMFLOUND', 'SEABASSTAU', 'CODPOLLOCK', 'BLUEFISH', 'WEAKFISH', 'STRIPEDBAS', 'TUNA', 'SHARKS', 'BILLFISH', 'BONITOALBA', 'SCUP', 'RED_HAKE', 'LOBSTER'];
var features = FeatureSetByName($map, 'Ocean Prime Fishing Grounds', fields, false);
var aDict = Schema(features);
var aArray = aDict['fields'];
var output;
for (var j in aArray) {
    //console(aArray[j]['name'] + ' ' + $feature[aArray[j]['name']])
    if ($feature[aArray[j]['name']] == 1 && aArray[j]['name'] != 'OBJECTID') {
        output += aArray[j]['alias'] + TextFormatting.NewLine;
    }
}
return output;

 

View solution in original post

2 Replies
KenBuja
MVP Honored Contributor

You can specify the fields returned for the Schema array using

var fields = ['SUMMFLOUND', 'SEABASSTAU', 'CODPOLLOCK', 'BLUEFISH', 'WEAKFISH', 'STRIPEDBAS', 'TUNA', 'SHARKS', 'BILLFISH', 'BONITOALBA', 'SCUP', 'RED_HAKE', 'LOBSTER'];
var features = FeatureSetByName($map, 'Ocean Prime Fishing Grounds', fields, false);

Now this will also include the OBJECTID field, so you can test for that when looping through them

if (dict['name'] == i && dict['name'] != 'OBJECTID'){

 

0 Kudos
KenBuja
MVP Honored Contributor

And with some more testing, a shorter way of doing this

 

var fields = ['SUMMFLOUND', 'SEABASSTAU', 'CODPOLLOCK', 'BLUEFISH', 'WEAKFISH', 'STRIPEDBAS', 'TUNA', 'SHARKS', 'BILLFISH', 'BONITOALBA', 'SCUP', 'RED_HAKE', 'LOBSTER'];
var features = FeatureSetByName($map, 'Ocean Prime Fishing Grounds', fields, false);
var aDict = Schema(features);
var aArray = aDict['fields'];
var output;
for (var j in aArray) {
    //console(aArray[j]['name'] + ' ' + $feature[aArray[j]['name']])
    if ($feature[aArray[j]['name']] == 1 && aArray[j]['name'] != 'OBJECTID') {
        output += aArray[j]['alias'] + TextFormatting.NewLine;
    }
}
return output;