How to return label value for a selected item?

5082
4
07-08-2016 05:43 PM
Joseph_Kinyon
Occasional Contributor II

I would like to use the xpath function jr:choice-name in a calculation to return the label of a selected answer--rather than the answer itself.

The item selected is from a "select_one_external species" filtered using a formula for the category in the choice_filter for that item.

I understand there is some trouble if it returns zero, so it is often nested in an if statement to check.

Would it be possible to calculate:

if(string-length(${species}) != 0,jr:choice-name(${species},'${species}'),'none observed')

I have tried inserting the above into the calculation as well as using:

calculate="if(string-length(${species}) != 0,jr:choice-name(${species},'${species}'),'none')"

I either get a blank for the whole calculation or the term "false"

My goal is to add the value of the label to a concatenation in the instance_name on the settings tab so that the instance includes the concatenated name of the observer, the date, and the species name (instead of the stored value of the unique species code) for quick review and sorting in the field.

My concatenation using this formula is working correctly:

concat(${observer}, "-",${species},"-",${date},"-",${time})

4 Replies
Joseph_Kinyon
Occasional Contributor II

Does jr:choice-name work in Survey123?

0 Kudos
Joseph_Kinyon
Occasional Contributor II

FYI, confirming that testing the following calculation does not work to return the label for the field named choice ${choice} with the type and corresponding list name "select_one yes_no"

     if(string-length(${choice}) != 0,jr:choice-name(${choice},'${choice}'),'nothing chosen')

The MS Excel form with this calculation in it converts properly.

Survey123 gives no errors when the form calculates it.

However, nothing is returned for either options in the if statement.

This same if statement works when the "jr:choice-name" function is replaced with a string.

Cheers,

Joe

0 Kudos
AlekKreiger
New Contributor III

It appears this can be achieved by using the pulldata() function against external data stored in a .csv file as described here . If you store the labels in a field in what is referred to as the "<returnColumn>" on the page referenced, you can use them to populate a 'calculate' field type in your xls form (this is how I did it anyway).  You may be able to get it to work within the concat() formula itself but I haven't tested it.

Note:  tested with Survey123 Connect version 2.0.35 and survey accessed via web app.

Joseph_Kinyon
Occasional Contributor II

Alek,

I'd love to see your spreadsheet and .csv. 

The javarosa term jr:choice-name is not implemented in Survey123 is one reason it doesn't work.

The pulldata is also possible but the pulldata only works on some elements the last time I tested (and not the ones needed/wanted), will look into it again and thanks for that clarification.

Cheers,

Joe

0 Kudos