Autogenerated Ids


Identifiers are unique strings generated by the system, which can be used to identify a beneficiary. Usually, these have special patterns - prefixes, suffixes, special numbering patterns etc, which aid users in understanding a beneficiary.

ID Generation in Avni

In usual systems, identifiers are generated from a central place because we need them to be unique. However, the Avni Android app is expected to work offline. Offline ID generation is possible, but is done differently. IDs in Avni are generated in batches and sent to a user.

There is a special form element type called ID. If you configure a form element to be of ID type, then the Avni android app will automatically retrieve the next ID from this batch and assign it as the value.

Advanced - It is also possible to create rules that modify the final ID that is stored for the beneficiary. For example, if there is the need of adding a date to the final ID being generated, you would write a ViewFilter rule that will use the generated ID and append a date to it.

Identifier sources

It is possible to have multiple IDs being generated at the same time. Each ID type is called an identifier source. An identifier source will have a certain type (discussed later), prefix (optional), minimum and maximum lengths and can be assigned to a catchment.
The type of an identifier source determines the strategy used to generate IDS of that source. There are currently two types available. The only difference between them is the place where the prefix is stored.

  1. User pool based identifier generation - Here, a pool of users within a catchment share the same prefix. The prefix is stored within the identifier source within options. Every user asking for ids is provided with a set of ids prefixed with this value.
  2. User based identifier generation - Here, the prefix is stored in the "idPrefix" value of the user's settings.


  1. User pool based identifier generation - overlaps in ID for the same identifier source not allowed.
  2. User based identifier generation - Two users in the same organisation cannot have same prefix. This check is case in-sensitive.

Queries to analyse existing data is available here -


1. Create Identifier Source from admin section:

  1. Give name
  2. Choose type - User pool based identifier generator or User based identifier generator. Difference between the two is explained above.
  3. Choose catchment
  4. Choose batch generation size. This is the number of identifiers that will be generated at once and be sent to client app on sync. If your field users can not sync for a long time then you should estimate how many identifiers they may need.
  5. Choose minimum balance. This is useful to make sure that your users get a warning to sync before they run out of identifiers.
  6. Choose Min length and max length. This specifies the min and max length of the generated identifiers.
  7. You will get an option to add Prefix if you chose User Pool Based Identifier Generator in the Type field(1.2). This prefix will be shared by all identifiers generated for users sharing the same identifier source.

2. Create Identifier User Assignment from admin section:

  1. Choose User. The user that you select will start getting auto-generated ids once they Sync.
  2. Choose Identifier Source. This is the resource that you created in Step 1 above(Create Identifier Source from admin section).
  3. Enter initial identifier to be generated for this user. It should also include the prefix. E.g. if you had set the prefix to be ANC and min length to be 3, and you want the identifiers to start from 100 then the value of this field could ANC100.
  4. Enter last identifier to be generated for this user. System will not generate any identifiers beyond this. E.g. If your prefix is ANC, max length is 4 and you want identifiers only till 2000 then this could be ANC2000.

3. Create a question in the form with concept type Id

  1. In the form where you want the auto generated identifier, do create a question with concept type Id and select the identifier source.

What’s Next