I have the following relevant expression:
${TRANSECT_NUM}='4' or ${TRANSECT_NUM}='8' or ${TRANSECT_NUM}='12'or ${TRANSECT_NUM}='16'or ${TRANSECT_NUM}='20' or ${TRANSECT_NUM}='24'or ${TRANSECT_NUM}='28'or ${TRANSECT_NUM}='32'or ${TRANSECT_NUM}='36'or ${TRANSECT_NUM}='40'
The expression works fine, but is there a way to condense, so it is not so lengthy? Something like selected$(TRANSECT_NUM} = 4,8,12,16, etc.?
The TRANSECT_NUM field is an integer field and calculated based on the count of another field, so I can't use the selected expression.
$(TRANSECT_NUM) in ('4','8','12') etc. with other values
Thanks Michael,
Tried this with the following expression and received a message that it could not understand the expression.
${TRANSECT_NUM} in ('4','8','12','16','20','24','28','32','36','40')
As far as I've found, Survey123 does not support the 'value in list' type of expression, however ODK indicates that the selected() function might support a similar thing - however, in testing this with S123, ESRI does not appear to support it being used in this way. That leaves us with a few workarounds, but they are typically not as clear or explicit or easy to understand as the built up query that you have. In your case, queries such as:
(${transect} < 41 and ${transect} mod 4 = 0) or (${transect} = 28)
or
contains("4,8,12,16,20,24,28,32,36,40", string(${transect})) and string-length(${transect})>0
appear to work with your specific list, however users coming to work on your survey in the future might not clearly understand what your expression is trying to do.
Being frustrated in the past that Suryey123 did not appear to support this type of thing, this is what I came up with:
1. Add a select multiple where the default value is set to include all the valid choices. Set the body::esri::visible to hide this question (use something like 1=2), and set the bind:esri:fieldType to null so that no field is created in for this.
2. use the formula: selected(${multiple_selection_question}, string(${TRANSECT_NUM})) in the relevant.
Here is my tested and functioning sample:
Of course you need the choices:
This approach can easily be reused, although it is relatively static, if you needed to generate the valid choices on the fly, you might need a very long choice list or external csv.