Multiple Choice Constraint - A List of values

2007
8
09-26-2017 09:40 AM
PaulSchneider
Occasional Contributor

Regarding Ishmael's post on Multiple Choice questions, I see the ability to review individual items within a select_multiple type; is it possible to review if a list of items are selected?

I have a client who is observing activities, and which observed activities are unsafe, both fields reference the same choice list.  I'd like to add a constraint that ensures that if a item is selected in the 'unsafe' field it is also selected in the 'observed' field.  Can something along these lines be done? 

typenamelabelconstraintconstraint_message
select_multiple ActivitiesobservedObserved Activities
select_multiple ActivitiesunsafeUnsafe Activitiesselected(${observed}, ${unsafe} )Unsafe Activities must also be noted as Observed above
0 Kudos
8 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Paul,

I think that this is possible, but a bit more complicated.  The basic unit of the constraint check is

For a given value, is it selected in observed?  If so, is it selected in unsafe?

This translates to the following in XLSForm formulas:

if(selected(${observed}, 'a'), selected(${unsafe},'a'), true)

if( observed has the value a selected, then determine if unsafe selects value a, otherwise the constraint is met)

You would repeat this for each value in the list, joining the parts to gather with 'and' so that if one is not met, the entire thing false:

if(selected(${observed}, 'a'), selected(${unsafe},'a'), true) and if(selected(${observed}, 'b'), selected(${unsafe},'b'), true) and ...

Note this is to ensure that if it has been selected in observed, that it appears in unsafe- this would let unsafe have additional values that are not selected in observed.

AndrewHargreaves2
Occasional Contributor III

Hi James Tedrick

I'm following the above logic, but getting nothing. Here's my constraint statement in my [COVER_LEVEL] row:

if(selected(${COVERED_OVER}, 'NO'), selected(${COVER_LEVEL},'UNKNOWN'), true)

If I set {COVERED_OVER}= 'NO' and ${COVER_LEVEL}= 'UNKNOWN' my message fails to appear. Any advice is gratefully received.

Thanks

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Andrew,

This is on a constraint, correct?  The formula you have translates to:

If covered_over is no, cover_level must be UNKNOWN; if covered_over is not no, any value is valid

If you you want unknown to not be a valid answer when covered_over is no, you would want:

if(selected(${covered_over}, 'no'), not(selected(${cover_level}, 'unknown')), true)

AndrewHargreaves2
Occasional Contributor III

One more for you James Tedrick

Can the logic you describe above for  the orginal questions contain an 'or'? Sadly, it appears not as I'm trying the below with no success:

if(selected(${COVERED_OVER}, 'NO'), not(selected(${COVER_LEVEL}, 'UNKNOWN')), true) or if(selected(${COVERED_OVER}, 'UNKNOWN'), not(selected(${COVER_LEVEL}, 'BELOW_GRADE')), true)

The first part, before the 'or', works fine upon validation however the second half of the statement is failing to do anything.

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Joining two constraints together, you probably want to use 'and' instead of or.  and will require both statements to be true for the answer to be valid, or will require one of the statements to be true:

Statement (expression1 __ expression2)Result
true and truetrue
true and falsefalse
false and truefalse
false and falsefalse
true or true

true

true or false

true

false or true

true

false or false

false

0 Kudos
AndrewHargreaves2
Occasional Contributor III

James Tedrick‌ that's just my point; If either statement is TRUE then the constraint is also TRUE. For example:

if(selected(${COVERED_OVER}, 'NO'), not(selected(${COVER_LEVEL}, 'UNKNOWN')), true) or if(selected(${COVERED_OVER}, 'UNKNOWN'), not(selected(${COVER_LEVEL}, 'BELOW_GRADE')), true)

should result in a constrain triggering:

if COVERED_OVER is NO, COVER_LEVEL must NOT be UNKNOWN

or

if COVERED_OVER is UNKNOWN, COVER_LEVEL must NOT be BELOW_GRADE

However, as described only the statement before the 'or' works to trigger the constraint....

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Andrew,

You're actually wanting the reverse - constraints fire when a statement evaluates as FALSE (that's why there's not() in the function I created - to flip it to a "can't be <value>").  You do want to use 'and' (all the requirements must be met) instead of 'or' (one of the requirements must be met).  

OR is a little confusing because it strays a bit from conversational English:

Q: Do you want to go out for dinner or cook at home? 

A: Yes

AndrewHargreaves2
Occasional Contributor III

Thank you James Tedrick

#SyntaxKing!

0 Kudos