Survey 123 Report Template - Syntax for if function using multiple answers from a select_one question

1935
5
Jump to solution
03-02-2023 09:02 AM
ChristopherDawe
New Contributor III

I am trying to work out the syntax for a report to only show a section of the report when certain options are selected. 

i know that i can use ${if fieldname | selected: "option1"}...${/} which return true if that value is selected, however i have 141 options in my choice list which then relate to 25 section of the report. 

Survey 123 connect syntax for these options would involve a regex with something along the lines of if(regex(${fieldname},"option1 | option2 | option3 | option4",value if true, value if false) but i cant seem to get the same syntax working in reports

I have tried ${if fieldname| selected: "option1 | option2 | option3 | option4"}...${/} but this doesnt appear to work.

Does anyone know what the correct syntax may be? Additionally if this also works for select_multiple that would be great but i understand that may open up a whole other set of issues!

0 Kudos
1 Solution

Accepted Solutions
Katie_Clark
MVP Regular Contributor

I had a similar question about syntax when I asked this question: https://community.esri.com/t5/arcgis-survey123-questions/conditional-statement-syntax-in-survey123-r...

Maybe try something like this? The double pipe || being the "or" operator in Javascript syntax....

${if fieldname == “1” || field == “2” || fieldname == "3"}X${/}

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek

View solution in original post

5 Replies
Katie_Clark
MVP Regular Contributor

I had a similar question about syntax when I asked this question: https://community.esri.com/t5/arcgis-survey123-questions/conditional-statement-syntax-in-survey123-r...

Maybe try something like this? The double pipe || being the "or" operator in Javascript syntax....

${if fieldname == “1” || field == “2” || fieldname == "3"}X${/}

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
ChristopherDawe
New Contributor III

Thanks Katherine, exactly what I needed!

AnthonyJonesRSK
Occasional Contributor II

Hi Christopher, 

I came across your question as I was trying to find out how to display parts of my feature report dependent on whether certain options had been picked in a select_multiple. Similar to your case I needed sections to display when a number of potential options had been selected. Unfortunately the documentation for report templates only shows how to do this for one option selected in a select_multiple and I couldn't find any solutions in the forums. After much testing I think I've worked out the syntax. It needs to look something like the below;

${if (SelectMultipleQuestion | selected:"Option1")||((SelectMultipleQuestion | selected:"Option2")||(SelectMultipleQuestion | selected:"Option3")}TEXT TO DISPLAY${/}

The key things seems to be the use of parentheses to separate the statements. I've only tested this on one form so far but everything seems to be working as expected. Hopefully this is of use to you or others.

Now if someone can just provide the syntax to display something when it's not selected in a select_multiple that would be great!

Cheers

Anthony

0 Kudos
Katie_Clark
MVP Regular Contributor

Hi Anthony,

I haven't actually tested this, but would adding an exclamation mark in front of the parentheses work?

i.e.

${if !(questionName | selected:"Option1")}TEXT TO DISPLAY${/}

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
AnthonyJonesRSK
Occasional Contributor II

Hi Katherine,

Thank you so much for your reply. I can indeed confirm that your syntax does work. Seems that the key to a lot of this is putting the parentheses in the right place!

Really appreciate that, it will come in very useful for one of the reports I'm working on.

Cheers

Anthony