0

I'm trying to write an expression for a pop up in ArcGIS Online that will display the name of the fields if there is a specific value under those fields for each feature. I adapted the following script that I found online.

var i = 0
var features = [];

function addvalue(feat) {
    if (!IsEmpty(feat)) {
        features[i++] = feat;
    }
}

addvalue($feature.schoolCommGardenQuarter);
addvalue($feature.smarterLunchQUARTER);
addvalue($feature.schoolWellnessQuarter);
addvalue($feature.keysNAPSACCquarter);
addvalue($feature.healthConcessionsQuarter);
addvalue($feature.foodPantryBackpackQuarter);
addvalue($feature.farmMarketorPopUpQuarter);
addvalue($feature.rydQUARTER);
addvalue($feature.directEd);
addvalue($feature.onetimeRYDEventQuarter);

return Concatenate(features, ";")

This runs without issue but it returns the values as a concatenated list (such as [YES;NO;YES;YES]). I want to edit the above script so that it returns a text string of the field names that have YES as a value.

I have since edited my script so that the if statement evaluates for the 'yes' value. I still am having trouble figuring out how to access and return the field names rather than the 'yes' values. var i = 0 var features = [];

function addvalue(feat) { if (feat == 'Yes') { features [i++] = feat; } }

addvalue($feature.schoolCommGardenQuarter); addvalue($feature.smarterLunchQUARTER); addvalue($feature.schoolWellnessQuarter); addvalue($feature.keysNAPSACCquarter); addvalue($feature.healthConcessionsQuarter); addvalue($feature.foodPantryBackpackQuarter); addvalue($feature.farmMarketorPopUpQuarter); addvalue($feature.rydQUARTER); addvalue($feature.directEd); addvalue($feature.onetimeRYDEventQuarter);

return Concatenate(features, ";")

  • Suggest you look at the help file. Your first issue is to test IF the value is yes. Look here for code examples. – Hornbydd May 8 '18 at 15:11
  • Thanks. Possible values in this dataset include 'yes', 'no', and blanks. I overlooked the inclusion of 'no' in this script. – Thomson Gross May 8 '18 at 15:40
2

The only way I could see doing it is to add an argument in your function for the field name. You have to add it manually to each addvalue call

function addvalue(feat, field) {
    if (feat == 'Yes') {
        features[i++] = field;
    }
}

addvalue($feature.schoolCommGardenQuarter, "schoolCommGardenQuarter");
0

I just had to do this, came across your question and have a solution.

Iterate $feature as below. Drop this into the Arcade playground and see:

var returnstring = "AllValues"
for (var i in $feature) {
    returnstring = returnstring + ":" + i + ":" + $feature[i]
}
return returnstring

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.