Difference between revisions of "SurveyCTO Dynamically Populated Choice Lists"

Jump to: navigation, search
Tag: Redirect target changed
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Best Practice == <onlyinclude>
#REDIRECT [[SurveyCTO Choice Lists#Dynamically Populated Choice Lists]]
Sometimes we want to ask a respondent to select one or several answers out of answers the respondent have given earlier in the interview. For example, we might want to ask who in the household out of the household members listed in the household roster module is currently employed. It is possible to do this by dynamically load previous answers as answer options.</onlyinclude>
 
Any answer can be used in dynamic choice lists, but when using variables inside a repeat group, one more extra step is required because we cannot reference a field that was inside a repeat group directly. We ned to first store the value of this field so that SurveyCTO knows what is the item we are referring to. The calculate field is the intermediate step required. The same applied if you want to build a relevance with the value of a field that filled inside a repeat group.
 
== Coding Example ==
[https://docs.google.com/spreadsheets/d/1jkqL2gUGlOGWXPyUF940V4BjH0iDjsxMt6168ncSr_s Here is a code example] of how the answers to a field inside a repeat group are used to dynamically load the answer options for a select_one or a select_multiple question.
 
This example dynamically loads answers from a repeat group to be able to use them later in the questionnaire: as relevance, or dynamically populated choice lists for example. If you were to dynamically load answers from fields not inside a repeat group, then you simply reference those fields directly in the choice tab.
 
Note that this coding example can be improved in many ways. It has excluded some possible improvements in order to highlight the functionality discussed in this article. The most obvious improvement would be to filter the answer options so that only the answer options needed are displayed. See the section about choice filters.
 
Note that SurveyCTO will let you upload a form on the server even if you used directly an answer from a repeat group in your programming without referring it with a calculate field. The error message will appear only on the tablet, when swiping to the next question.  In that respect, always test your form before the field data collection.
 
== Back to Parent ==
This article is part of the topic [[SurveyCTO Coding Practices]]
 
[[Category: SurveyCTO Coding Practices ]]

Latest revision as of 18:12, 20 July 2023