Arcade Conditional Visibility Statement Help

1258
3
Jump to solution
09-07-2021 05:30 PM
Henry
by
Occasional Contributor II

Hi,

Still working with Arcade here and there - trying to get some Field Maps configured with conditional visibility similar to Relevant fields in forms used in Survey123 but I'm quite a newbie to Arcade.

I've managed to get conditional visibility working for single values so that a field won't appear if a specific value is selected in a previous field. Ex: $feature.name == 'value'.

How would that work for a number of options? Say I wanted to restrict the field from appearing in the form for values "a, b, c" OR 'd" entered in a previous field?

I suspect it would use If-Else, but I don't want the field to populate with another value - I just don't want it to appear!

Maybe I'm overthinking it . . .

Henry
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Check out the function Includes. If you define a list of values, you can use this to return a boolean true/false.

var restricted_list = ['a', 'b', 'c', 'd']
var prev_field = $feature['field_name']

// Will return 'true' if previous field is in restricted list
return Includes(restricted_list, prev_field)

It may make more intuitive sense to equate "true" with "visible", though, so you can simply re-write that with an added !, which negates whatever comes after it.

!Includes(...)

Which will return "true" if the previous field is not in the restricted list.

- Josh Carlson
Kendall County GIS

View solution in original post

3 Replies
Ewout_de_Graaff
New Contributor III

You can combine multiple conditions with an AND or OR statement as in SQL. You do this in the case of Arcade with a double && for AND and a double || for OR.

Example AND: if($feature.field1 == "a" && $feature.field2 == "b" && $feature.field3 == "c")

Example OR: if($feature.field == "a" || $feature.field == "b" || $feature.field == "c")

Example combination: if($feature.field1 == "a" && $feature.field2 == "b" || $feature.field1 == "c" && $feature.field2 == "d")

Hopefully you get on with this. Good luck!

GIS specialist bij Terra Nostra
jcarlson
MVP Esteemed Contributor

Check out the function Includes. If you define a list of values, you can use this to return a boolean true/false.

var restricted_list = ['a', 'b', 'c', 'd']
var prev_field = $feature['field_name']

// Will return 'true' if previous field is in restricted list
return Includes(restricted_list, prev_field)

It may make more intuitive sense to equate "true" with "visible", though, so you can simply re-write that with an added !, which negates whatever comes after it.

!Includes(...)

Which will return "true" if the previous field is not in the restricted list.

- Josh Carlson
Kendall County GIS
Henry
by
Occasional Contributor II

Thanks for the tips, both! Tried the methods out and they're working great.

Henry