Select to view content in your preferred language

Multiple values for condition in IIF attribute rule statement

940
1
10-08-2020 09:00 AM
SFM_TravisBott
Frequent Contributor

I am trying to create an immediate calculation attribute rule for a feature class in ArcGIS Pro (that I hope carries over when published as a feature service on AGOL). 

I understand the basic syntax: IIF(condition, trueValue, falseValue). So if I wanted to create a rule that would take a value in my fictitious FoodName field and auto-calculate my FoodType field, I could do some thing like...

var food = $feature.FoodName
IIF(food == 'Carrot', 'Vegetable', 'Fruit')

This would, whenever the value 'Carrot' appears in the FoodName field, calculate the FoodType field to 'Vegetable.' My question: How do you pass a list of values to the condition in these statements? This has been surprisingly not straight forward to find online. 

For instance, I would like the values 'Carrot', 'Celery', 'Parsnip', and 'Broccoli' to all to auto calculate to 'Vegetable.' Is it possible to pass a list to the condition, rather than writing multiple IIF statements? What is the preferred syntax?

0 Kudos
1 Reply
JoshuaBixby
MVP Esteemed Contributor

A couple different ways to tackle this type of situation.  If you want to stick with arrays instead of dictionaries, membership lookup is through IndexOf

var veggies = ['Carrot', 'Celery', 'Parsnip', 'Broccoli']
var items = ['Parsnip', 'Apple']

for (var k in items) {
    Console(IIf(IndexOf(veggies, items) > -1, 'Vegetable', 'Fruit'))
}

Use Console Function to output messages.

Vegetable
Fruit‍‍‍‍‍‍‍‍‍‍‍
0 Kudos