Define a Record ID using AutoNumber
When adding Records to an App, it is often a good idea to have a Unique ID for each Record in the App for referencing purposes. One way to do this is by determining a standard format for the ID. Let's say that we are building a Projects App. We can ensure that each Project has a Unique ID by stating an ID of the format PROJ-0021 where the number is a 4 digit number that increments by one each time a new Record is created.
Step 1:
The first step is to add an AutoNumber Field that increases in value by one every time a new Record is created. Create a Field called AutoNumber and select the Field Type as a Number.
One of the parameters on the Field config is 'AutoNumber'. Tick this property and then set 'Next Auto-Number' to be the first number that you want in the next Record created. This number will increase by 1 every time a new Record is created.
This Field does not need to be added to a Template, it can be hidden and used in the expression to set the Project ID.
NOTE : Autonumbers are only allocated when the record is created. When users are offline and a record is created, the auto number will only be allocated when the record is synchronised when the user is back online
Step 2:
The next step is to create a Text Field with an expression to set the ID, to use 'PROJ' & Autonumber this expression would be 'PROJ - ' + [AutoNumber]. This expression will run on creation of the Record to set a Unique ID for the Project.
If you want to fix the ID to a set number of digits you could prefix the AutoNumber with 0s. So to get the format 'PROJ' + XXXX you could use:
'PROJ - ' + if([AutoNumber] < 1000, '0','') + if([AutoNumber] < 100, '0','') + if([AutoNumber] < 10, '0','') + [AutoNumber]
-
Official comment
Auto Number Tip:
Please note that Auto-numbering only occurs on creation of new records. To update existing records with a new auto-number field in place, un-tick auto-number in the field details, manually fill out the number in each of the existing records (on many records do a quick export to excel, fill out numbers, then re-import), then turn auto-number back on.
Comment actions
Please sign in to leave a comment.
Comments
1 comment