Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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. 

Table of Contents
stylenone

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.

Table of Contents
stylenone

Generating a Unique ID

Step 1: Create a property in custom user data

  • Create Custom User Data property for each mobile user called "prefix"

  • Assign each user a prefix value, for example, 10, 11, 12, 13, 14 and so on. In order to determine your prefixes, you need to think about how many beneficiaries you expect each mobile user to register. In this example, we do not expect the user to register more than 10,000 beneficiaries, ever, and our prefixes and suffixes match that. 

    • You can assign this prefix when you add the mobile users individually, or in bulk. 

    • Notably, this prefix can also be a letter or a code, it does not have to be numeric.

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:

...