Help Needed with Automatic Household Code Generation

Hi everyone,

I'm currently building a household survey form in ODK and would appreciate some assistance.

I'm aiming to have ODK automatically generate a unique code for each household during the data collection process.

If anyone has experience implementing this functionality in ODK, I'd be grateful for your guidance.

Perhaps you could share some resources or best practices on achieving this.

Thanks in advance for your help!

Best regards,

Gerald
household-registration.xlsx (578.4 KB)

The search function of this forum can provide a lot of discussions and examples for your issue, please: https://forum.getodk.org/search?context=topic&context_id=46020&q=generate%20unique%20id&skip_context=true.

Enumerate the HH before data collection, and create a numeric field to let data collectors enter HH# manually as per enumaeration list. Prefix this no. with an ID string generated using other relevant variables in your survey using the concat() function. If you don't want to enter HH# manually for including in the ID, you can try using uuid() function to include alpha-numeric UUID in your ID string.

1 Like

Thank you very much @joybindroo but I do not understand what you want to explain. Please can you do a quick sample form of how it can be done?


@gerald_thomas The calculations shown in this snapshot can be used for including an auto generated ID in your survey that utilizes uuid() function. See how 'pkey' variable, the primary key in this example, is generated using concat() function - concatenating the auto generated random uuid string (learn more about UUID here) with other variable values of concern. Variable Q1c, Q1d, and Q1e are the variables of concern, storing Facility name, District, and Sub-District name in this example, and you can see how they are supplied as input parameters in the concat() function to generate required primary key string.

Probably the calculation shall be done only once. So, pack it in once(..). Otherwise, recalculation will be done, e.g. on open, edit, save! See https://docs.getodk.org/form-logic/#form-logic-gotchas.

If you want a visible field, use text type with read_only (and once(...) calculation). Also, setting a default might work here.

2 Likes

@joybindroo thank you very much for your help. It is working now

1 Like