Select to view content in your preferred language

selected-at() not working properly when pushed into webapp

1038
4
Jump to solution
04-14-2023 11:05 AM
townofmountainvillage
Emerging Contributor

I have created a survey for a forestry project in survey123 connect that has some semi-complicated xml and html formatting. Everything works fine in the viewer of survey123 connect, but once I publish it into AGOL the selected-at() function seems to not be working. 

The goal of the question is to identify the persons top 5 choices from a large list and then rank them based on the order they selected. The solution I found to populate the label value associated with the name value was to import an identical CSV file to the list the xml is pulling from in the choices tab.

typenamelabelcalculation
calculatequestion_desc pulldata('survey123_forestry', 'description', 'item', ${question3})
    
calculateq3_answer1namesselected-at(${question3}, 0)
calculateq3_answer2namesselected-at(${question3}, 1)
calculateq3_answer3namesselected-at(${question3}, 2)
calculateq3_answer4namesselected-at(${question3}, 3)
calculateq3_answer5namesselected-at(${question3}, 4)
    
note <h5> <font color="#00395A"> First Choice: </font> </h5>pulldata('survey123_forestry', 'description', 'item', ${q3_answer1})
note <h5> <font color="#00395A"> Second Choice: </font> </h5>pulldata('survey123_forestry', 'description', 'item', ${q3_answer2})
note <h5> <font color="#00395A"> Third Choice: </font> </h5>pulldata('survey123_forestry', 'description', 'item', ${q3_answer3})
note <h5> <font color="#00395A"> Fourth Choice: </font> </h5>pulldata('survey123_forestry', 'description', 'item', ${q3_answer4})
note <h5> <font color="#00395A"> Fifth Choice: </font> </h5>pulldata('survey123_forestry', 'description', 'item', ${q3_answer5})

 

This works in survey123 connect perfectly, but when I publish it, the order in which the person selects the choices have no effect on the order of ranking. It automatically puts the choices in the order they exist in the csv. 

Is the selected-at() function not working in the webapp? Does this function only work in the survey123 mobile app? Or does it have to do with the pulling from the csv? Would love any insight!

 

 

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ZacharySutherby
Esri Regular Contributor

Hello @townofmountainvillage

Thank you for reporting this! The issue isn't so much with the selected-at() function it's more how the Survey123 website handles multiple choice questions which has a downstream impact on the selected-at() function. Survey123 stores multiple choice questions as a comma separated list ex. (choice1,choice3,choice5). What Survey123 Connect and the field app do is append the selected response to the end of the list maintaining the order in which the choices were selected (this is why selected-at() works well in this environment). What the Survey123 website is doing is instead of inserting the selected choice at the end of the list it's inserting it in the choice's index in the choice list (this is why selected-at()) isn't working as expected in this environment). I've logged an internal issue to correct this behavior in the website, please feel free to reach out to Esri Technical Support to log an Enhancement as well to track progress on the issue. 

Based on the brief snippet of your survey in the issue description as a workaround for the time being I would suggest checking out the rank question type to see if that would work in your use case as that maintains choice order in the web app allowing selected-at() to function as expected.  

Thank you,
Zach

View solution in original post

4 Replies
ZacharySutherby
Esri Regular Contributor

Hello @townofmountainvillage

Thank you for reporting this! The issue isn't so much with the selected-at() function it's more how the Survey123 website handles multiple choice questions which has a downstream impact on the selected-at() function. Survey123 stores multiple choice questions as a comma separated list ex. (choice1,choice3,choice5). What Survey123 Connect and the field app do is append the selected response to the end of the list maintaining the order in which the choices were selected (this is why selected-at() works well in this environment). What the Survey123 website is doing is instead of inserting the selected choice at the end of the list it's inserting it in the choice's index in the choice list (this is why selected-at()) isn't working as expected in this environment). I've logged an internal issue to correct this behavior in the website, please feel free to reach out to Esri Technical Support to log an Enhancement as well to track progress on the issue. 

Based on the brief snippet of your survey in the issue description as a workaround for the time being I would suggest checking out the rank question type to see if that would work in your use case as that maintains choice order in the web app allowing selected-at() to function as expected.  

Thank you,
Zach
AJ_devaccount
Frequent Contributor

@ZacharySutherby I have a simple rank question, followed by text fields to get the value at each index position using the selected-at() function. It seemed to work in the field app, but doesn't seem to work in the web app. Is this function not usable for rank questions in the web app. When I tested it with a multiple choice question, it seemed to work in the web app. Thanks for your help!

0 Kudos
SMDSAdministrador
Occasional Contributor

A tip: if your intention is only to return the label (and not the name) of a select_multiple question, you don't need to use pulldata for that. You can use the jr:choice-name function, in association with the selected-at function, directly in the questions that are displayed to the user.

jr:choice-name(choice_name, 'question')

Used for select_multiple questions. It returns the label associated with the name of the choice in the given question. The selected-at() function must be used to extract the label for individual answers. Be aware that the question must be defined inside quotes.

Something like this:

jr:choice-name(selected-at(${question3}, 0), '${question3}')

townofmountainvillage
Emerging Contributor

Thank you for this suggestion! I tried to get this function to work and it just wasn't giving me the answer I wanted. So when I found the other solution and it worked I just decided to go with that. 

0 Kudos