Survey123 regex calculation

3023
4
10-16-2018 07:26 AM
EricS
by
Occasional Contributor

I have a question that I want to use regex calculation to populate. if(regex(${timing},'emerging'),'emerging_issue','critical_issue')

My reason for this post is because the question that the regex refers to has a relevant formula to not display if a certain choice is selected in the survey.  Because of the regex formula it defaults to the second choice "critical_issue"when really I want it to default to a "None" answer.  I put none in the default column and it works in surveyconnect version 2.9.3 but it does not work in the app version 3.1.68.  Do you have any suggestions on how to make this work?  Is there a different way other than the regex formula?

0 Kudos
4 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Eric,

Can you provide the XLS file or a screenshot of the question's configuration? From your description, it sounds like the formulas is functioning correctly - if the regex is false, then the value 'critical_issue' will be set.

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Eric,

The XLS file is a little too stripped down to try to replicate.  Based on the description in the writeup, is sounds as if you need to change the second value in the if statement to reflect the 'None' choice - that would cause the select_one to be set to that choice when the timing question is not 'emerging'.  I would also suggest using the selected() function in this case as opposed to regex() since the timing question is a single choice question.

0 Kudos
EricS
by
Occasional Contributor

James

Thank you for taking the time to review my issue I am sure you are very

busy. I have revised my writeup on the situation as I think I was not

explaining myself well. Please see the attached word doc.

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Eric,

Thanks for clarifying.  The issue is that you want the value of 'Emerging/Critical' question applied to the Status question when 'Emerging/Critical' is relevant, but set to None otherwise, correct?  In that case, I would suggest changing your if() statement to look for whether the 'Emerging/Critical' question has a value, and None otherwise.  This can be done with:

if(count-selected(${timing}) > 0, ${timing}, 'None')

This assumes the name value of the status choices match the name values in the emerging/critical list and that the 'None' choice in status has a name with the value of 'None'.

0 Kudos