ODK 2.0: Issue with using calculated value from main form in sub-form

What is the problem? Please be detailed.
In a form being designed for a household level survey where 2 individuals have to be surveyed per household, a unique ID for each survey respondent (“respondent_id_number”) is generated using the “generate_respondent_id” function in the calculates sheet. Screenshots of the survey section sheet as well as the calculates sheet are below with relevant portions highlighted in yellow -

Survey section:

Calculates sheet:

When this calculated “respondent_id_number” is passed to a subform for recording the details about household members by including it in the model sheet of the sub-form, clicking “create new instance” of the subform fails to initialize and move forward. Instead, the app cycles back to the main menu with list of surveys/forms to pick from.

The queries sheet in the main form -

The model sheet of the main form -

The model sheet from the sub-form -

An explanation and/or fix would be very helpful.

What you have you tried to fix the problem?
This problem does not arise when “voter_id_number” which is an alpha-numeric user input value (not a calculated value like “respondent_id_number”) is passed to the sub-form through the model sheet. To check if the reason for the problem is somehow the contents of “respondent_id_number”, the “generate_respondent_id” function has been modified for debugging purposes to assign it the value of “voter_id_number” without any modifications. This may mean the issue has been isolated to passing calculated values to a sub-form.

What ODK tool and version are you using? And on what device and operating system version?
I’m using ODK 2.0 and Application Designer 2.1.0.

Dear @Satish_Ravishankar,

Thanks for all the detail in your explanation! So I can think about this problem from two angles. The first is using your current structure, what might be the problem? I am wondering if the fact that you have, in the main form queries sheet, the selection be the same thing as you are assigning, if that is causing the problem, because it may be that you can’t simultaneously select and assign. The selection should be the household id or something like that, not the respondent id, because you want the sub-form to be all the respondents within the households.

The second approach to think through is, setting aside your current structure, what are your goals? Is there any reason you need to program in assigning the respondent id? Is there any reason you cannot just let ODK assign a unique id to the subform (it will do this automatically)? You can also let ODK assign a unique id and still number people in the household by counting sub-forms (e.g. how many subforms does this household have already finished, and the new one is that +1). That would be using async_assign – I am attaching an example of this for q301, where we make the line # in the household by counting how many other members are there.

quest1_03_0.xlsx (55.2 KB)

Hope one of these ways of thinking helps!