Follow

Generating a Unique Number/Code

Often you will need to generate unique number or code as part of a particular Form screen's data output.

This is common in cases like order numbers, invoice codes, document ids and many other scenarios.

 

You can achieve this by using a formula to create a text value that you assign to the Dynamic Value property of the designated Form field.

Essentially you'll concatenate various bits of data together to create a meaningful, but reasonably unique code.

 

Note we say "reasonably unique".  

This is because ultimately the formula will generate a unique code for the local device context.

It is important to use data elements like the date/time or the user's details to ensure that the resulting code cannot be duplicated on other users or devices.

 

Often we are asked if it is possible to have a central sequential number that all devices are aware of.

This way the codes on all form entries could be sequential and numbered in order of entry/capture.

 

We support this scenario primarily on the Data Template side by making available a special built-in placeholder called {{%ENTRYID}}.

This special placeholder is not currently available for form use - it is only available on Data Templates.

So you can produce numbered outputs if you use data templates.

Refer to the "Built-in Placeholder" article under the Data Templates section of our documentation.

 

Other than the ENTRYID option on data templates, we don't support form-side central numbering since there is no guarantee about network connectivity at the time of capturing the form.

So what happens if the user is disconnected at the time of capturing a form?

Also bear in mind that there can be a time lag between form entry capture on the device and when the data actually gets uploaded to the server (again depends on network connection and other device factors).

 

As such we recommend generating codes in a device specific manner.

 

If you must have a central sequential number, then you need to handle this on your backend system.

i.e. when form entry data is moved into your relevant backend system, at that point assign each entry a new centralized sequential number.

 

 

We recommend you use something like the counter() function concatenated with the userexternalid()/useremail() and say with format-date() on today()/now() as well.

The External Id on users is particularly useful for storing something like a payroll id or other code that has meaning in the ultimate destination system.

 

Here are some examples of formulae to generate device-specific unique codes:

 

uuid(10) gives something like: X7E5F3A2L3

 

random() gives something like: 0.14935942 which you can then multiply/round etc to get the desired precision

 

counter() gives you a sequentially increasing number that is device-specific.

 

concat(format-date(now(), 'yyyyMMdd'), '-', counter()) gives something like: 20140313-39

 

concat(format-date(now(), 'yyyyMMdd'), '-', userexternalid(), '-', counter()) gives something like: 20140313-USER1-39

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk