What is the structure of an if/else statement in Survey123?
I'm trying to check the username of the user, if true then grab the answer from a select one question, if not then just grab the username from the username question type. No luck so far
From the documentation:
if(condition, a, b)
Where:
The linked page has plenty of functions and operators to help you set up your if condition. If you're still stuck, describe exactly what you're trying to check and how, and someone can try to help you further.
I have this:
if(${Name}='Internal', ${Call_In_Name}, ${Name})
Where Name is the name of the account
Call_In_Name is a select one answer
This is going into a textbox. I want to grab Call_In_Name if the username (Name) is equal to "Internal", else just grab the username (Name) and put it into the textbox
There is also a requirement to overwrite what's in textbox if the username is already in there and the user clicks on the select one question
So if I understand correctly, it sounds like you have two conditions to trigger ${Call_In_Name} being used in the textbox:
For the second condition, you state "if the username is already in there and the user clicks on the select one question." Are there any situations where ${Call_In_Name} is selected, but you still want to use ${Name} instead? If not, then this should probably do what you need:
if(string-length(${Call_In_Name})>0, ${Call_In_Name}, ${Name})
This checks to see if ${Call_In_Name} has been answered, and if so, grabs that value. If not, ${Name} is used instead.
And just in case someone has 'Internal' for ${Name} but tries to skip answering ${Call_In_Name}, you can put this condition in the required column for ${Call_In_Name}:
if(${Name}='Internal')
(note, conditionally required questions apparently don't work in web forms)
With this setup, the textbox will always equal the ${Call_in_Name} as long as that question is answered. If instead you want to use ${Name} all the time unless A) it's 'Internal' or the user wants to optionally override it, you'll need to do that with at least another question and some additional statements.
To provide some info to your response:
The workflow is the following:
In that use case, your initial if/then statement should work just fine (I'm assuming your username is 'Internal'). Why is there anything to overwrite in the textbox? It should start blank, and populate only via the if/then calculation:
Are you trying to recalculate ${Name}, or do you have something set up in the default column for the textbox question? Are you able to share your csv file?
Incidentally, you could also use the coalesce() function and get rid of the ${Name} line:
This will always input the AGOL username unless there's an answer selected in ${Call_In_Name}.
That's perfect thanks!
The property('username')='Internal' formula is giving me an error.
Also with ${Name}='Internal' as the relevant field, when a user logins in they don't see the fields, which is great. But when they submit data it doesn't grab their username or email from my pulldata function.
Another question though. Can you put an if on pulldata()? I want to check if the user is me (the internal account), if true then grab the email from a csv file I have as it contains emails for all users...since I can't pull from the AGOL account as it would pull my email and not the user's email.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.