I am trying to use the formula here:
jr:choice-name(selected-at(${select_multiple}, choice_index), '${select_multiple}')
To combine the labels from a select multiple into a new field. My exact calculation is here:
jr:choice-name(selected-at(${Photographers}, choice_index), '${Photographers}')
This previously worked in this survey before, it matches exactly the Survey123 Formula Documentation.
In the Survey123 app I receive the following error in the field this calculation is in:
ReferenceError: choice_index is not defined in expression: (Then lists the expression again here)
I know I can do a workaround with a series of concatenations and if statements, but this should work and has worked before. Just not sure what's going on here. Anybody else experiencing this?
In the selected-at() function, choice_index must be an integer. From the same documentation, the selected-at() function "returns the name of the choice selected for the given number, counted starting from zero; for example, '2' will return the third selected choice." Note that the choice index can either be a number you specify in the expression, or a question placeholder, e.g.
jr:choice-name(selected-at(${Photographers}, 4), '${Photographers}')
or
jr:choice-name(selected-at(${Photographers}, ${choice_num}), '${Photographers}')
where ${choice_num} is an integer question.
The jr:choice-name() function returns the label of one choice only. So if you want to get the labels for all selected Photographers into one field, you'd need a separate jr:choice-name() expression for each selection. One way to do this could be to have a separate hidden question for each choice, then concatenate all these into a final question.
I will raise an issue to make the documentation clearer, as the descriptions for selected-at() and jr:choice-name() functions differ when referring to the choice index. Thanks for bring this to our attention!
Hope this helps,
Best, Jim