Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How do I generate a unique ID?

Issue

I need to generate unique IDs for my project. The IDs need to start with "REF" and be followed by numbers that increase by 1 each time. I want to trigger the ID generation with a button click and display the ID in a pop-up message. I plan to store these IDs in a database, but I don't need continuity across different sessions. I am not sure how to handle sequence generation, but I was advised to use the storeValue function and initialize the first value on page load. Another suggestion was to use a custom JS library to install the UUID library for generating unique IDs.

Resolution

To generate unique IDs with a specific pattern using a button click, the first step is to initialize the ID value. This can be done using the storeValue function and setting it to run on page load.

One approach to generating new IDs every time the button is clicked is to use a JS object with a getNewId function that increments the ID value by one and stores it using storeValue. The function can then return the new ID with the desired prefix.

If continuity in ID values across different sessions is desired, the most recent value can be saved to a database when generated and loaded on page load to ensure up-to-date ID generation. Another option is to use the custom JS libs feature to install the UUID library and generate a unique ID using {{UUID.generate()}}.