Survey123 one field OR another must be filled in "Required"

1748
6
Jump to solution
02-26-2020 11:24 AM
BradGeorgic
New Contributor III

I have 2 fields one called email and the other phone.  I want to make it so that either one of them have to be filled in for the survey to be sent.  How do I set the required and constraint fields?  Any help is appreciated

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Esteemed Contributor

For these it always ends up in a dependency cycle.  So I use a 3rd field like this.

typenamelabelhintconstraintconstraint_messagerequiredrequired_messageappearancedefaultreadonlyrelevantcalculation
textfieldAfieldA
textfieldBfieldB
calculatecheckfieldscheckfields.!=''Must fill out fieldA or Bcoalesce(${fieldA}, ${fieldB})

Someone may have another idea.  Hope it helps.

View solution in original post

6 Replies
DougBrowning
MVP Esteemed Contributor

For these it always ends up in a dependency cycle.  So I use a 3rd field like this.

typenamelabelhintconstraintconstraint_messagerequiredrequired_messageappearancedefaultreadonlyrelevantcalculation
textfieldAfieldA
textfieldBfieldB
calculatecheckfieldscheckfields.!=''Must fill out fieldA or Bcoalesce(${fieldA}, ${fieldB})

Someone may have another idea.  Hope it helps.

BradGeorgic
New Contributor III

Doug Brwoing with the WIN!  Thank you that solved it!

0 Kudos
RichardBuford
New Contributor

How did you solve this. Which one is set to required?

0 Kudos
DougBrowning
MVP Esteemed Contributor

Neither is set to required.  You instead set the constraint on field 3 to !=''.  This will fire if both are blank but not if either one has a value.

0 Kudos
mfavorito1995
New Contributor II

Has anyone tried this solution recently? I had built a survey in Survey123 Connect a few months back implementing this solution, but it does not appear to work anymore. I tried setting up similar constraints on multiple fields, but they survey goes through without any issues.

0 Kudos
Czapiga_Jason
New Contributor II

I like Doug's solution, but we solved this by creating a select one question (${contact}) that asks the user "how do you wish to be contacted" with (text message, email, phone) as options.  Then you make the email and phone questions (both set to required) visible/hidden with a relevant expression.  selected(${contact},'email') on the email question or selected(${contact},'phone') or selected(${contact},'text_message').  if the question is relevant, it will be required.

0 Kudos