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.
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
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
type | name | label | hint | constraint | constraint_message |
select_ multiple colors | color_prefs | What colors do you like? | Select three | count-selected(.)=3 | Select exactly three. |
Table 2: Choices
list_name | name | label |
colors | red | Red |
colors | blue | Blue |
colors | yellow | Yellow |
colors | green | Green |
colors | orange | Orange |
colors | purple | Purple |
Table 3: Survey with jr:choice()
type | name | label | hint | calculation |
select_multiple colors | color_prefs | What colors do you like? | Select three. | |
calculate | color_0 | jr:choice-name( selected-at(${ color_prefs}, 0), ’${color_prefs}’) | ||
calculate | color_1 | jr:choice-name( selected-at(${ color_prefs}, 1), ’${color_prefs}’) | ||
calculate | color_2 | jr:choice-name( selected-at(${ color_prefs}, 2), ’${color_prefs}’) | ||
note | color_note | Selected 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!
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
type | name | label | calculation |
hidden | your_field_name | The label you want to use | concat(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.
Hi ! I suggested a solution using Excel TEXTJOIN function and javascript that prevents the pain with larger lists or the need deal with extra separators, and allows to keep the choice order.
You can find the details in this thread:
Re: How to return all labels from a select multipl... - Esri Community
Hope it helps and saves some time !
Léo