AnsweredAssumed Answered

Arcade Expression to Change Multiple Values in a Field for Each Record

Question asked by stacey.plumley on Jul 28, 2020
Latest reply on Jul 29, 2020 by stacey.plumley

Hello - I'm trying to change multiple values in a field for each record (e.g., SK, CO, BT) to different values (e.g. Sockeye, Coho, Bull Trout) to display in a web map pop-up using Arcade. I've tried this Arcade expression but it returns the error: Execution Error:Field not Found:

 

var spcode = Dictionary('SK', 'Sockeye', 'CH', 'Chum', 'PK', 'Pink', 'CO', 'Coho', 'CK', 'Chinook', 'SH', 'Steelhead', 'SRCT', 'Sea run cutthroat', 'RT', 'Resident trout', 'BT', 'Bull Trout');

var values = Split($feature.Species, ',');

var numcode = Count(values)

var spindex = 0;

var splist = [];

if (numcode > 0) {

    for (var i in values) {

        splist[spindex] = spcode[values[i]];

        ++spindex;

    }

return splist;

 

If the array is a variable, this expression works in the Arcade Playground:

 

var spcode = Dictionary('SK', 'Sockeye', 'CH', 'Chum', 'PK', 'Pink', 'CO', 'Coho', 'CK', 'Chinook', 'SH', 'Steelhead', 'SRCT', 'Sea run cutthroat', 'RT', 'Resident trout', 'BT', 'Bull Trout');
var values = ['CH', 'BT', 'SH'];
var spindex = 0;
var splist = [];
for (var i in values) {
splist[spindex] = spcode[values[i]];
++spindex;
}
return splist;

 

I've also tried a function to create an array of the field values, similar to the second expression, but get the same error as the first expression:

 

function fieldarr(inField) {

    var values = Split(inField, ',');

    var num = Count(values)

    var cdindex = 0;

    var cdlist = [];

    if (num > 0) {

        for (var i in values) {

            cdlist[cdindex] = values[i];

            ++cdindex;

        }

    } 

return cdlist;

}

var spcode = Dictionary('SK', 'Sockeye', 'CH', 'Chum', 'PK', 'Pink', 'CO', 'Coho', 'CK', 'Chinook', 'SH', 'Steelhead', 'SRCT', 'Sea run cutthroat', 'RT', 'Resident trout', 'BT', 'Bull Trout');

var fieldlist = fieldarr($feature.Species)

var numcode = Count(fieldlist)

var spindex = 0;

var splist = [];

if (numcode > 0) {

    for (var i in fieldlist) {

        splist[spindex] = spcode[fieldlist[i]];

        ++spindex;

    }

return splist;

 

I'm stumped - any help would be greatly appreciated!

Outcomes