I am trying to the following Esri Technical Support example/logic https://support.esri.com/en/technical-article/000020969 as a template in my survey. However instead comparing one option to another I am trying to modify the formula example to check from the following choices
1) ImpairedHearing
2) ImpairedVision
3) Developmental/CognitiveDisability
4) DifficultyUnderstandingEnglish
5) DifficultyUnderstandingWrittenMaterial
6) NoneAbove
7) DontKnow
8)Refused
but want to use the following options 6) NoneAbove, 7) Don'tKnow, or 8)Refused to compare with one of the 1-5 choices.
I have tried the following formula:
not(selected(., ‘ImpairedHearing’,'ImpairedVision', 'Developmental/CognitiveDisability', 'DifficultyUnderstandingEnglish', 'DifficultyUnderstandingWrittenMaterial' ) or selected(., 'NoneAbove') or selected(., 'DontKnow') or selected(., 'Refused'))
it works sometimes but sometimes it doesn't. I have also tried using and instead of or and that hasn't worked either. Is there a way create a constraint with this type of logic?
Solved! Go to Solution.
A tip: I highly recommend not trying to create these sorts of calculations in a single field, precisely for the reasons that you have just experienced.
It's a lot easier when you have long, complex calculations to break them down into individual parts. That way you can see what part of the calculation is failing to evaluate correctly.
In this case, I recommend that you create one field that evaluates whether the user has selected a "known" answer, then another field to evaluate whether they have selected an "unknown" answer.
Once you have those fields evaluating correctly, set your constraint based on whether they have selected both a "known" and an "unknown".
I have attached a working example of this below.
FWIW, the problem with your calculation is is that you aren't using any joiner (eg "and" or "or") in your expression. So the calculation is asking the app to look for an answer that is literally:
‘ImpairedHearing’,'ImpairedVision', 'Developmental/CognitiveDisability', 'DifficultyUnderstandingEnglish', 'DifficultyUnderstandingWrittenMaterial'
That will only happen when you have selected every answer from 1-5. You entire expression will only evaluate to true when you select all 8 answers at once.
You could do this in a single field by using a calculation similar to:
not ((selected(.,'ImpairedHearing') or selected(.,'ImpairedVision')) and (selected(., 'NoneAbove) or selected(.,'DontKnow')))
But I really suggest that you not do that sort of thing. It's a real pain to debug.
A tip: I highly recommend not trying to create these sorts of calculations in a single field, precisely for the reasons that you have just experienced.
It's a lot easier when you have long, complex calculations to break them down into individual parts. That way you can see what part of the calculation is failing to evaluate correctly.
In this case, I recommend that you create one field that evaluates whether the user has selected a "known" answer, then another field to evaluate whether they have selected an "unknown" answer.
Once you have those fields evaluating correctly, set your constraint based on whether they have selected both a "known" and an "unknown".
I have attached a working example of this below.
FWIW, the problem with your calculation is is that you aren't using any joiner (eg "and" or "or") in your expression. So the calculation is asking the app to look for an answer that is literally:
‘ImpairedHearing’,'ImpairedVision', 'Developmental/CognitiveDisability', 'DifficultyUnderstandingEnglish', 'DifficultyUnderstandingWrittenMaterial'
That will only happen when you have selected every answer from 1-5. You entire expression will only evaluate to true when you select all 8 answers at once.
You could do this in a single field by using a calculation similar to:
not ((selected(.,'ImpairedHearing') or selected(.,'ImpairedVision')) and (selected(., 'NoneAbove) or selected(.,'DontKnow')))
But I really suggest that you not do that sort of thing. It's a real pain to debug.
Thank you Laurence for the response.
I will take your advice and break it out into smaller logic. In the meantime we added a note with relevant logic to have a warning come popup in real-time (not when submitted) to notify the user they have selected a combination that isn't acceptable.