Select to view content in your preferred language

Survey123 Pre-Select Questions

636
2
Jump to solution
09-16-2022 12:03 PM
EmilyMalvini
New Contributor

Hi,

We have a CSV file that stores product attributes, e.g., colors. In our survey, we would like the user to be able to update the colors for that product. When a user selects a product from a drop-down list, we want a read-only question that queries the CSV file and returns a list of the current colors for that product. This question would serve two purposes: 1) allow us to store the information in our database to see what the colors were before the user made any changes; 2) be FYI for the user so they can see the current colors.

Then, the second question would be a select_multiple question displaying a list of all available colors with the currently assigned colors pre-selected. The user would then be able to select/de-select the colors as necessary to update.

My questions are:

  • How would I create the first question? If using a custom Javascript to return an array, is there an example of the script I can reference? My first attempt at this was to use a select_one question with a choice filter that returns the values based on the product that the user selected in a previous question. However, the returned values are not stored when the user submits the survey.
  • For the second question, how would I design the question to return a list of all possible values with the currently assigned values pre-selected?

Thank you!

0 Kudos
1 Solution

Accepted Solutions
LaurenceTait
Occasional Contributor II

In Survey123, you can't use Javascript with local files - so no working with CSV files. To do what you want, you'd need to load the CSV to your server and convert it to a JSON and then work with the JSON.

But I don't think JS is the optimal solution for what you want to do. If I understand you correctly, this can all be accomplished quite easily using the 'pulldata' and 'select_one_from_file' functions and setting the default of the second question to the response for the first. 

I'm not sure what you mean when you say that returned values are not stored when the user submits the survey. So long as the type isn't bound to null, it should be uploaded to the database.

LaurenceTait_2-1663548457136.png

 

LaurenceTait_1-1663548418927.png

 

 

View solution in original post

2 Replies
LaurenceTait
Occasional Contributor II

In Survey123, you can't use Javascript with local files - so no working with CSV files. To do what you want, you'd need to load the CSV to your server and convert it to a JSON and then work with the JSON.

But I don't think JS is the optimal solution for what you want to do. If I understand you correctly, this can all be accomplished quite easily using the 'pulldata' and 'select_one_from_file' functions and setting the default of the second question to the response for the first. 

I'm not sure what you mean when you say that returned values are not stored when the user submits the survey. So long as the type isn't bound to null, it should be uploaded to the database.

LaurenceTait_2-1663548457136.png

 

LaurenceTait_1-1663548418927.png

 

 

EmilyMalvini
New Contributor

I was overthinking things. Thank you so much!! This worked. 

0 Kudos