What do you need help with?
Search the knowledge base, browse our resources, and visit our forum for more detailed information
Search the knowledge base, browse our resources, and visit our forum for more detailed information
Last updated: 11 Jan 2022
There are times you may want to generate a unique serial number for each and
every form in a project. This article discusses various workarounds on how to
create unique serial numbers using the calculate
question-type.
This method works best with Enketo web forms. It uses a calculation function to create a unique serial number based on the date and time to the first millisecond. Although this method may not meet all your needs, it should give you an illustration of how much you can stretch calculate functions.
Create a
calculate
question type in either the formbuilder or XLSForm and use the formula
below.
concat(substr(today(), 0, 4), substr(today(), 5, 7), substr(today(), 8, 10), substr(now(), 11, 13), substr(now(), 14, 16), substr(now(), 17, 19))
The same formula can work as an integer
question when working in
an XLSForm.
In the example, when you preview the deployed form in Enketo, you should be able to see the serial number within the note question as shown in the image below:
This example shows how to create unique serial numbers from existing, already
defined variables in your form by using the
concat()
expression in a calculate
question type. The example is shown as an
XLSForm, but can just as easily be done within the formbuilder.
survey
type |
name |
label |
calculation |
---|---|---|---|
text |
Q1 |
Region Name |
|
text |
Q2 |
District Name |
|
text |
Q3 |
Cluster Name |
|
text |
Q4 |
Village Name |
|
text |
Q5 |
Household Serial Number |
|
calculate |
Q1_C |
substr(${Q1}, 0, 3) |
|
calculate |
Q2_C |
substr(${Q2}, 0, 3) |
|
calculate |
Q3_C |
substr(${Q3}, 0, 3) |
|
calculate |
Q4_C |
substr(${Q4}, 0, 3) |
|
calculate |
ID |
concat(${Q1_C}, ‘-’, ${Q2_C}, ‘-’, ${Q3_C}, ‘-’, ${Q4_C}, ‘-’, ${Q5}) |
|
note |
note_id |
Your Unique ID for this form is: ${ID} |
When you preview the example in Enketo web forms, the serial number will be presented within the note question as shown in the image below:
Did you find what you were looking for? Was the information clear? Was anything missing?
Share your feedback to help us improve this article!
KoboToolbox is maintained by Kobo Inc.