Generating a Unique ID for beneficiaries

Many programs assign their beneficiaries externally-facing IDs. Using a combination of custom user data and a counter you can assign unique IDs to your beneficiaries. Since CommCare works offline you must create a portion of the ID that is based on the user case, since each user can be working offline simultaneously. 

Note on Case IDs versus Unique IDs

CommCare assigns every case a globally unique case ID that is a 36-character long alphanumeric string. You should always use the case ID to link your data on the backend. These instructions detail how to create an easily readable user-facing ID for beneficiaries. This should not be used to link data on the backend or for any data analysis.

 

Generating a Unique ID

Step 1: Create a property in custom user data

Step 2: Create a counter in your registration form

Step 3: Create a hidden value to generate the unique ID

Example

Let's look at an example of how this would work in an app.

  • In step 1, my user case property is called prefix.

  • In step 2, the counter that I made is saved as the property child_count.

  • So finally, in step 3, the calculation that I would put into my beneficiary_id calculate condition box would be:

if(#form/child_count < 10, concat(#user/prefix, '000', #form/child_count), if(#form/child_count < 100, concat(#user/prefix, '00', #form/child_count), if(#form/child_count < 1000, concat(#user/prefix, '0', #form/child_count), "")))

If my user prefix was 12, and I registered my 5th child of the day, the ID that CommCare would generate for this child ID would be: 120005.