Using 'jr:choice-name' for multiple selections

2349
3
04-29-2020 09:30 AM
KerryKang
Occasional Contributor III

Hello all, 

Is there any syntax using 'jr:choice-name' for all/ any selections in multiple choices? I hope to get labels in the attributes no matter how many answers are selected. I am aware that 'at' can be used to pull out the value in the specific order, but not sure how I can apply it to the entire answers. 

0 Kudos
3 Replies
BrettStokes
Esri Contributor

Hi Kerry,

Unfortunately this isn't possible using jr:choice-name(), which will only use the label to populate the attribute if one selection is made. Did you come up with a workaround or alternative to this workflow? If so, please share it on the forum.

Thanks,

Brett

BenjaminAu
New Contributor

Hi Brett/Kerry,

I am totally new to GIS domain. So happens I came across this website with the extensive methods to invoke within XLS for Survey123 Connect. Within the PDF there is a section describing the jr:choice() for multiple choice questions. Below is the example used to select exactly three colors:

Table 1: Survey

typenamelabelhintconstraintconstraint_message
select_
multiple
colors
color_prefsWhat colors do you like?Select threecount-selected(.)=3Select exactly three.

 

Table 2: Choices

list_namenamelabel
colorsredRed
colorsblueBlue
colorsyellowYellow
colorsgreenGreen
colorsorangeOrange
colorspurplePurple

 

Table 3: Survey with jr:choice()

typenamelabelhintcalculation
select_multiple colorscolor_prefsWhat colors do you like?Select three. 
calculatecolor_0  jr:choice-name(
selected-at(${
color_prefs},
0),
’${color_prefs}’)
calculatecolor_1  jr:choice-name(
selected-at(${
color_prefs},
1),
’${color_prefs}’)
calculatecolor_2  jr:choice-name(
selected-at(${
color_prefs},
2),
’${color_prefs}’)
notecolor_noteSelected colors:${color_0}
<br>
${color_1}
<br>
${color_2}
 

 

Snapshots from the PDF are attached here for your reference. Pardon for the resolution, it is snipped based on the PDF. For more information you can visit this link and download the PDF for its full information: https://docs.getodk.org/

I was able to use such concept on my form to produce the expected output.

Hopefully it helps!

0 Kudos
daeronicus
New Contributor

I revived this only to provide a more simple solution for this.

You only need one hidden field using concat formula parameterized like this:

concat(jr:choice-name(selected-at(${your_question},0), '${your_question}'), ', ', jr:choice-name(selected-at(${your_question},1), '${your_question}'),', ', jr:choice-name(selected-at(${your_question},n), '${your_question}'))

You will have to increase n as many times as answers you want to capture.

This expression will generate a list like this

selection 1, selection 2, selection n, ....

Of course you can replace ', ' with any character you want to use for separate the choices, you could use ' | ', or ' - ', etc

 

The XLSForm will look  like this

typenamelabelcalculation
hiddenyour_field_nameThe label you want to useconcat(jr:choice-name(selected-at(${your_field_name},0), '${your_field_name}'), ', ', jr:choice-name(selected-at(${your_field_name},1), '${your_field_name}'),', ',jr:choice-name(selected-at(${your_field_name},2), '${your_field_name}'))

 

The column bind::esri:fieldType will be esriFieldTypeString and bind::esri:fieldLength can be 1000 length.

Later you can filter this on a dashboard with a filter applied to your hidden field using the contains parameter with the choice you want to show.

Hope this helps.