You would like assign a random ID to new user sign-ups or generate coupon codes.
Since Text Formulas and Equations recalculate every time a record is updated, the random function ["random()"] will set a different value each time.
The last step in these instructions allow for this value to be stored, if you would like to store the original value.
If this your first time creating an app, you'll need to know some basics about adding objects and fields. You can start by watching our "Introducing Knack" video tour and then working through the "Data: About Your Database" article.
Add a new text formula field
- Add a text formula field called "Random ID" to an object. We'll use the Person object for this example.
Set text formula field to value
- Click to edit the Random ID short text field.
- Click in the formula field and enter the random() function, with any number of characters that you want your ID to have, eg. random(5).
Add a new short text field
- On the same Person object, add a new short text field called ID.
Store Value: Add a conditional rule to short text field
If you'd like to store the first random number generated, you can continue with the following steps.
- Click to edit the ID short text field.
- Click on the "Conditional Rules" tab, and then checkbox "Add conditional rules".
- Add a rule:
- When "ID" "is blank",
- Value Set "to a record value" "Random ID".
This way, it will only be set once; once ID is no longer blank, it will not reset.
Notes & Troubleshooting
Do not use Random ID elsewhere in your app, since it will change with each record update.