Generating a Reference Number
I remember way back when I first started using Podio one of the things I struggled with right at the start was generating something like a Project reference number. Now in Tape there are a few ways to achieve a unique reference number, depending on what you actually want to achieve.
The Unique ID field
Section titled “The Unique ID field”Tape provides a built-in unique number field which gives your record a unique number within an app. You can also set the field to include a prefix or suffix to further customize the reference number.
Thats the simplest way to generate a reference number, however that may not always be sufficient depending on your use case. As there are a few restrictions:
- The number can’t be padded with zeros (e.g. 0001, 0002, etc.)
- The prefix will not be carried over if the field is call/used in a different context.
The Record ID
Section titled “The Record ID”Tape allocates a Record ID to each record, now this one is different to the Unique ID field as it is unique across the the whole of Tape every single record ever created. It also means that the numbers are now quite large 167113606
as an example. The other thing about this number is that there is not a field specificaly for this ID and infact untill recently you could only get it via an automation. However you can now access it in a record calculation field.
parseInt(@record_id,10)
@record_id
Build your own
Section titled “Build your own”If neither of the above options work for you, you can always build your own reference number using a combination of fields and a calculation field.
The way I do it
Section titled “The way I do it”I generaly use a combination based on date, Unique ID and some custom text. For example if I was creating a reference number for a project I might endup with something like this:
To achive this we do need two fields plus a calculation field:
- A date field (e.g.
@created_at
) - this is oftern worth having anyway and can be hidden. - The Unique ID field (e.g.
@unique_id
) - again this can be hidden and is always worth having for use in automations. - A calculation field to combine them (e.g.
@reference_number
)
Your calculation field would then look something like this:
`PRJ${date_fns.format( @Created on , 'yy')}${String( @Unique ID ).padStart(3, '0')}`
now that is doing quite a lot in one line so lets write it a different way and break it down:
const text = 'PRJ';const year = date_fns.format(@Created on, 'yy');const paddedUnique = String(@Unique ID).padStart(3, '0');`${text}${year}${paddedUnique}`
- We need our prefix text:
const text = 'PRJ';
- We need our year:
const year = date_fns.format(@Created on, 'yy');
- We need our padded unique ID:
const paddedUnique = String(@Unique ID).padStart(3, '0');
- We need to combine them all together:
`${text}${year}${paddedUnique}`