These seems elementary, but I'm not finding it. I am building an attribute rule using Arcade and I would like to select several different values to meet a criteria. In SQL, I could do:
IF(fieldname IN ("value1","value2","value3"))
But in ARCADE, I can only seem to do:
IF(fieldname == "value1" || fieldname == "value2" || fieldname == "value3" )
Is there a way to simplify this expression like using the "IN" as in SQL?
Solved! Go to Solution.
You could try something like this?
var inputArray = ["xyz","abx","bob"];
var bool = Includes(inputArray, "bob");
return bool;
Although Includes will be the path moving forward, it is new in Arcade. If you are working with < 1.12 Arcade, the pattern is to use IndexOf.
That's a very good point! Using IndexOf doesn't return a boolean, so to simply check if it's "in" the list, it would look like this:
var some_list = ['value1', 'value2', 'value3', ... 'valueN']
if(IndexOf(some_list, $feature.field_name) != -1){
// It's in!
} else {
// It's not!
}
You could try something like this?
var inputArray = ["xyz","abx","bob"];
var bool = Includes(inputArray, "bob");
return bool;
You can accomplish this with Includes. Pass an array of values, and if your feature's field is included in the array, it will evaluate as 'true'.
var some_list = ['value1', 'value2', 'value3', ... 'valueN']
if(Includes(some_list, $feature.field_name)){
// It's in!
} else {
// It's not!
}
Although Includes will be the path moving forward, it is new in Arcade. If you are working with < 1.12 Arcade, the pattern is to use IndexOf.
That's a very good point! Using IndexOf doesn't return a boolean, so to simply check if it's "in" the list, it would look like this:
var some_list = ['value1', 'value2', 'value3', ... 'valueN']
if(IndexOf(some_list, $feature.field_name) != -1){
// It's in!
} else {
// It's not!
}
Thanks @jcarlson @JoshuaBixby @DuncanHornby , I must have an earlier version of ARCADE since only IndexOf worked...and like a charm! Sure wish there was a 'google translate' between programming languages, that should have been much easier to figure out than it was!