Select to view content in your preferred language

How to use an if statement to conditionally give users a choice, otherwise calculate the answer

104
3
Jump to solution
2 weeks ago
BradleyNissen1
Emerging Contributor

Hi there, 

I am trying to design a field that will automatically calculate an answer and be hidden, except in one scenario. So, when the user answers the question for "nest_type" (select_one), if they select "brood" or "inactive" then I would like the answer to the exclosure field to be calculated as "no". I also want it to be able to provide the user with a choice between "yes" or "no" if they select a nest_type of "nest". 

I am trying to write an if statement in the calculate field, but I'm not sure how to provide the "choice" if the conditions are false. So I'm trying: if(${nest_type} = "brood", "no", if(${nest_type} = "inactive_knownfate", "no", )) ... but I need to know what to put in the blank for that last question to essentially leave the question open to be answered. 

I have my relevant field set to another field: ${Nest_Present} = 'yes'

And I have it set in body::esri:visible as: ${nest_type} = 'nest'. 

I realize I could just have the question default to no and using the body::esri:visible field have the question not show up unless the nest type was nest, but I don't want to have the "no" already selected. 

Can someone help me get that "blank question" situation from an if statement? Thanks!

0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Esteemed Contributor

You can use empty string "" for this.  It will let the user add something.  You will see a recalc icon appear but as long as they do not tap it then the value will stay.  You can also use visible to hide it if you want.  Do not use relevant or it will be "" when it hides.  Visible hides the question but relevant changes the stored value to "".

You can also make your if simpler

if(${nest_type} = "brood" or ${nest_type} = "inactive_knownfate", "no", "")

Hope that helps

View solution in original post

0 Kudos
3 Replies
DougBrowning
MVP Esteemed Contributor

You can use empty string "" for this.  It will let the user add something.  You will see a recalc icon appear but as long as they do not tap it then the value will stay.  You can also use visible to hide it if you want.  Do not use relevant or it will be "" when it hides.  Visible hides the question but relevant changes the stored value to "".

You can also make your if simpler

if(${nest_type} = "brood" or ${nest_type} = "inactive_knownfate", "no", "")

Hope that helps

0 Kudos
BradleyNissen1
Emerging Contributor

Awesome, thank you! I actually figured that out and was coming back here to state it, but I'm still glad I posted since I didn't know you could use an OR statement with an if like that. Makes sense though since the conditions for either of those options have the same outcome. 

Are you suggesting I place this formula in visible? Right now I just have ${nest_type} = 'nest' in the visible column, which works well. This formula is in the calculation field. 

Thanks!

DougBrowning
MVP Esteemed Contributor

sounds like you have it correct