Code Help for IF Then using Drop Down List in Survey123

936
6
Jump to solution
06-16-2022 07:16 AM
AustinGootee
New Contributor III

Does anyone know the proper formatting for doing if then statements with a drop down list in survey 123.

First question is a drop down list with choices: A, B, C, D, E, F, G, ... (total options is close to 100, so i didn't want to do a single choice/select one format)

The second question is a single text line that I'd like to populate from the drop down answer in the first question: 

what I'd like to Do:

If question one is "E"

then question two equals "bird xyz"

Else if question one is "C"

then question two equals "dog xyz"

so on and so forth....

Else (if other is selected and filled in)

then question two is "other"

The current code I have:

if((${field_one}, "E"), "bird xyz"), elif((${field_one}, "C"), "Dog xyz"), elif((${field_one}, "B"), "cat xyz"), else("monkey xyz")

0 Kudos
1 Solution

Accepted Solutions
Katie_Clark
MVP Regular Contributor

Hmmm, well in this specific case I think you need an additional parentheses at the end to close the loops. I often write my expressions in a text editor with syntax highlighting so I can better see which parentheses are paired with which. 

Katherine_Clark_0-1655390911431.png

However, now that I see what you're doing (having the user choose the common name and populate the scientific name automatically), this really sounds like the ideal situation for pulling data from external CSV's. I make all my surveys in Survey123 Connect, and that's the method I use since I work in the environmental industry and the common/scientific name translation is a requirement for almost every survey!

Here's a great post from James Tedrick that can give you more info on that functionality. 

 

 

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

6 Replies
Katie_Clark
MVP Regular Contributor

I recommend taking a look at this post of mine from a few years back - I still reference it when I need to double check my nested if statement syntax! 

This is me taking a stab at the syntax you'd need - it should be really close at least!

if(selected(${field_one}, "E"), "bird xyz", if(selected(${field_one}, "C"), "Dog xyz", if(selected(${field_one}, "B"), "cat xyz", "monkey xyz")))

Hope that helps!

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
0 Kudos
AustinGootee
New Contributor III

Thank you, that seems like in general the right way to go, but i'm still getting an invalid syntax error (figured i'd try it on a few options before i add the code for all of the drop down items). Any ideas?

AustinGootee_0-1655390463879.png

 

0 Kudos
Katie_Clark
MVP Regular Contributor

Hmmm, well in this specific case I think you need an additional parentheses at the end to close the loops. I often write my expressions in a text editor with syntax highlighting so I can better see which parentheses are paired with which. 

Katherine_Clark_0-1655390911431.png

However, now that I see what you're doing (having the user choose the common name and populate the scientific name automatically), this really sounds like the ideal situation for pulling data from external CSV's. I make all my surveys in Survey123 Connect, and that's the method I use since I work in the environmental industry and the common/scientific name translation is a requirement for almost every survey!

Here's a great post from James Tedrick that can give you more info on that functionality. 

 

 

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
AustinGootee
New Contributor III

Thank you Survey123 Connect was definitely the way to go, I tried updating the code online with the extra parathesis and it still wasn't working. Now i just need to do some technical work to get the surveys to save onto our server and not the local machine, so anyone can access their designs, but that's a task for another day. 

As for the survey 123 connect and the csv tables, I was able to add the table and utilize it to fill in the scientific name based on a drop down list of common names (previously created online). Is there a way for me to use the common name field in the csv file that I added to create a drop down list, instead of having to fill in the choices sheet in the survey's excel file?

 

AustinGootee_0-1655484999133.png

AustinGootee_1-1655485723952.png

 

0 Kudos
Katie_Clark
MVP Regular Contributor

Yup! I recommend reading this post about external choice lists

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
AustinGootee
New Contributor III

Thank you so much @Katie_Clark!

0 Kudos