0

I am looking for an Arcade Expression for ArcGIS Online which does the following:

If the value from field A is 222,333 or 444 OR
If the value from field B is 222,333 or 444 OR
If the value from field C is 222,333 or 444
return "Problem detected"

else return "Everything fine"

I have just found a solution for one field, but it does not take care of Field B or field C:

if ( $feature.FieldA == 111) {
return "everything fine"
}
else if ( $feature.FieldA == 222) {
return "Problem detected"
}
else if ( $feature.FieldA == 333) {
return "Problem detected"
}
else if ( $feature.FieldA == 444) {
return "Problem detected"
}
else {

return "No Values"

}

Is this even possible in Arcade?

2 Answers 2

3

A solution is to use a nested IIF() statement. Imagine the data is this:

Input

Then you would run the following field calculate on it using this scripting logic:

var problemValues = [222,333,444];
var v = iif(($feature.fA == 111 && $feature.fB == 111 && $feature.fC == 111), "OK", iif((indexOf(problemValues,$feature.fA) != 0 && indexOf(problemValues,$feature.fB) != 0 && indexOf(problemValues,$feature.fC) != 0),"no values","problem"));
return v;

The result being:

Results

0

I suggest the following expression:

var problemValues = [222,333,444];
var fields = [
  $feature.fieldA,
  $feature.fieldB,
  $feature.fieldC
];

for (var i in fields){
  var v = fields[i];
  if(IndexOf(problemValues, v) > -1){
    return 'Problem detected';
  }
}

return 'Everything fine';

It's a little easier to read, and definitly easier to modify if you want to update the problem values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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