In this article, we will explore the process of utilizing a text formula field to generate a random ID.
If you require a random ID, such as for new user sign-ups or generating coupon codes, this guide will assist you in achieving that goal.
Since Text Formulas and Equations recalculate every time a record is updated, the random function: random() will set a different value each time.
The final step in these instructions enables the storage of this value, transforming the initial random number into a fixed ID.
1. Adding a New Text Formula Field
In the Data section of the Builder, you can add a text formula field to a table. For this example, let's use the Customers table.
Note: Avoid utilizing the "Random ID" field in any other part of your application as it will change with every update of a record.
Choose a name for the field, such as "Random ID". Input the following text into the Equation editor:
Tip: To learn more about available text formula functions, see our article here.
2. Store Value: Adding a Conditional Rule to a Short Text Field
If you wish to retain the initial random number generated, you can proceed with the following steps.
On the same table used for the step above, add a new short text field called "ID".
Select to edit the ID short text field.
Select on the "Conditional Rules" tab.
Check the checkbox for "Add conditional rules."
Add a rule:
When: "ID" "is blank
Set: "to a field value" > "Random ID"
In this case, the ID field will be set only once. Once the ID field value is no longer blank, it will no longer update.
Note: The short text field that you create must be placed below the text formula field in order to be populated correctly. This is due to the order of operations when calculating equations or formulas.