Compare string values

1252
7
Jump to solution
10-19-2017 07:53 AM
FinnianO_Connor
Occasional Contributor II

I have two similar scenarios that require strings to be compared:

1) A form with two select_one questions, each with a separate lookup list. There is some duplication between the lookup lists. When an value is picked for question 1, it should not be allowed as an answer to question 2. Can I compare the strings to raise an error for the user? Or is it possible to exclude the answer of question 1 from appearing in the lookup list for question 2?

2) Similar to scenario 1, except the two questions use the same lookup list. Again, the value chosen for question 1 should not be allowed as the value for question 2.

Is it possible to undertake string comparison in a constraint? so the constraint for question 2 would look like .!=${question1} or perhaps not(selected(.,${question1}))

Cheers,

Finnian

0 Kudos
1 Solution

Accepted Solutions
JohnathanHasthorpe
Esri Regular Contributor

HI Finnian

You can use the same approach for both 1) and 2) above (it does not matter if question 1 and 2 point to the same or a different choice list).

You would use a constraint as you described:

typenamelabelhintconstraintconstraint_message
select_one ratingchoice1Choice1
select_one ratingchoice2Choice2.!=${choice1}Choice1 can't  = Choice2

The above works - and will result in an error on submission if the the 2 choices are the same.

Cheers

John

View solution in original post

7 Replies
JohnathanHasthorpe
Esri Regular Contributor

HI Finnian

You can use the same approach for both 1) and 2) above (it does not matter if question 1 and 2 point to the same or a different choice list).

You would use a constraint as you described:

typenamelabelhintconstraintconstraint_message
select_one ratingchoice1Choice1
select_one ratingchoice2Choice2.!=${choice1}Choice1 can't  = Choice2

The above works - and will result in an error on submission if the the 2 choices are the same.

Cheers

John

FinnianO_Connor
Occasional Contributor II

Thanks for the reply John. Is it possible to raise an error before the point of submission? It would be preferable to have the user correct the answer before moving on with the survey. A more elegant solution would be to remove the answer for question 1 from the lookup list of question 2 (see https://community.esri.com/message/683657-excluding-a-value-in-a-list where i've gone into detail on what i'm trying to do). I haven't been able to get this working, so what you describe here will prevent the error making it to the database.

Thanks,

Finnian

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Finnian,

Survey123 currently doesn't check select against constraints as their values change.  We have an enhancement issue open to have a more consistent experience for constraint checking; I've added this example as a use case.

FinnianO_Connor
Occasional Contributor II

Thanks for the additional information James. Definitely with a long survey form, correcting errors at the time of data input would be the preferred choice.

0 Kudos
JamesTedrick
Esri Esteemed Contributor

I was also reminded that with Survey123 Connect you can place a warning message below the select multiple that has a relevant function the same as the constraint to alert the user while they are filling in the form; this provides some in-context alerting.

0 Kudos
FinnianO_Connor
Occasional Contributor II

That's a nice way to get a warning message to the user. Do you know is there a way to actually exclude the answer provided to question1 from the lookup list of question2. I tried to add logic to the choice_filter however this was unsuccessful (see https://community.esri.com/thread/194227-excluding-a-value-in-a-list ). 

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Finnian,

This is currently supported in the web for forms authored in Survey123 Connect; however, the field app & Connect don't support using/previewing choice list statements aside from equality comparisons.