Hi!
I’m trying to set a dynamic default where answers given outside a repeat group appear as default within it.
It is a household survey and at the beginning of the form I ask personal details of the respondent (name, age, sex, marital status) and of the head of the household if different from the respondent. I then ask the number of people in the household and use this value as the number of repeats for a household roster in a repeat group, where I ask the same questions for every member in the household (including the respondent and the head of the household).
To make the life of enumerators easier, I want the details filled at the beginning of the form to appear as defaults in the first iteration of the repeat group. If the respondent is not the head of the household, then the head of hh details should appear as default in the second iteration of the repeat group.
I tried adapting this code without success.
I also tried using the following formula in the calculation column within the repeat:
if(position(…)=1, ${name},if((position(…)=2 and ${head}=‘no’), ${head_name},’’))
where:
${name} is the name of the respondent
${head} is the question that asks if the respondent is the head of household
${head_name} is the name of the head of the household if different from ${name}
With the formula above the values appear as default but are deleted in ODK for the iterations where none of the conditions are met. Since ODK evaluates the formulas when saving the form, the single quotes at the end of the formula clear the values entered by the enumerator.
I also used triggers to avoid ODK Collect from evaluating the calculation when saving the form (triggers outside and within the repeat group) but values are emptied by the ‘’ at the end of the formula in every case.
Here’s my xls form. The tests mentioned above are in different tabs.
dynamic_default_test.xlsx (32.1 KB)
Your support is very much appreciated!