Select to view content in your preferred language

Survey123: Contains( ) formula in choice_filter

3447
3
07-09-2019 02:08 PM
ByronTsang
Occasional Contributor

Hello, Survey123 Experts:

I'm having a little trouble implementing a cascading select formula in my choice_filter column. 
I have two select_one questions with a choice_filter on the second question that filters my selection options based on the first question's response. I'm trying to use the contains( ) function to allow two different responses in question #1 (${wlsystem}) to yield the same response choices in question #2 (${subsystem}). The choice_filter formula I've used is formatted thus:
contains( [filter], ${wlsystem} )
Unfortunately, this formula breaks the select_one question entirely, yielding no choices for ${subsystem} whatsoever regardless of which response is selected in ${wlsystem}
For reference, I've attached an excerpt XLSForm that I'm working on.  For testing purposes, I added a calculated text field that verified the result of the contains( ) formula as well as a duplicate of the subsystem question using a simplified choice filter, but which requires a longer list of choices
Anybody have any recommendation on how to properly use the contains( ) formula with my choice_filter?
3 Replies
DougBrowning
MVP Esteemed Contributor

contains() returns true and false.  Choice filter is doing a lookup query.  

The last line looks right but the contains line would just calc to True.  That does not tell 123 what to go fetch.

Use the method in line 5.  You can build more complicated queries or add more columns to use in filtering.

I think that is what you are seeing.

ByronTsang
Occasional Contributor

Thanks Doug. This clarifies why the Contains() function wasn't yielding anything. I'm unfamiliar with the syntax rules for lookup queries. Is there some other way you know to implement a similar function where a single choice would be made available for any of several select_one responses to a prior question?  I'd like to avoid the method in line 5, if possible because of the need to duplicate some choices multiple times for each acceptable response. This table is just an excerpt of a much larger series of questions, but full implementation would yield a cumbersome and redundant long list of choices.

0 Kudos
DougBrowning
MVP Esteemed Contributor

Some of it was setup before me so there may be another way but I didnt find one.  On my big form with choice list of 5,000 they are all external_choices.  So I use multiple columns to break up the list different ways.

So my external choices looks like 

Then my choice filter does things like this

if I want all of them I do

fulllist=${fulllist}

If I want just Woody I do

Type=${woody}

If I want some combo I do 

Type=${woody} or Type=${herb} or Type =${unknown}

Or even

Foliar=${fulllist} or Type=${none}

One trick is it will not take text for some reason

So Type="Woody" will not work

So I just made dummy fields like this

But I am not basing any of this on a previous field so that gets harder.

For you it depends how many combinations you have.  You could make more columns instead of rows

So a column of M with a Y in it. Then a second column called E with Y in the right choices, etc.

But looking at yours I am not sure you can use a field name as the column filter name?  James may know.

So filter = ${wlsystem} turns into ${wlsystem} = "Y".

I guess it is tough without knowing your workflow.

Other times I just allow them to add bad values then check it with a constraint instead.

I would also read this page

Cascading and external selects—Survey123 for ArcGIS | ArcGIS 

0 Kudos