How to Prefill Respondent Name in the first line of a repeat group


1. What is the problem? Be very detailed.

2. What app or server are you using and on what device and operating system? Include version numbers.

3. What you have you tried to fix the problem?

4. What steps can we take to reproduce the problem?

5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.



I need help on how to Prefill the respondent's name as the first Household name in a repeat group. I want to record the respondent's name at the beginning of an odk questionnaire; and pre-record the respondent's name as the first name of the Household in a repeat group.



If you wish to only display the respondant's name as the first name in the repeat group - that is, the user can not change it - then you can do so using suitable show/hide logic on a read-only note.

However, I assume what you are asking is that you want to pre-fill a default value for (just) the first name in the repeat group, with the name of the respondant (correct?). In that case, try this:

Prefill_Default.xls (19.5 KB)
Prefill_Default.xml (1.5 KB)

The 'secret sauce' here is adding a calculation on the text input question:

once(if(position(..)=1, ${respondant}, ''))

Because it has a calculation, it will get re-evaluated continuously as you fill in the form. However, as a consequence of using once() the calculation will only update the result ${name} when ${name} is null/empty. And when it is null, which will be the case when you first start up the form, and it is the first entry in the repeat group (ie position(..)=1) then it will fetch the value of ${respondant} if it has one. Otherwise - or if you havent answered the respondant question yet - it will return null again, causing the calculation to continue to be re-evaluated until the ${name} question is answered, or in the case of the first entry you give a value to ${respondant}.

Note, a 'limitation' of this solution is that if you go back later and change the value of ${respondant}, its new value will not get picked up by the name in the first entry; because it already has a value, the once() effectively means the calculation doesn't fire again [but then that's arguably the definition of a 'default'... :wink: ]

Note, this may be used as a general approach to prefilling dynamic defaults from previous responses, not just for within repeat groups.

1 Like