Table of Contents

How to Set a Random ID

Lesley Updated by Lesley


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, so the first random number generated becomes a static ID.


If this your first time creating an app, you'll need to know some basics about adding tables, fields, pages, and views. You can start by reading our Builder Basics section

Other good resources can be found in our About Your Database and Working With Pages sections of the knowledge base.


Add a new text formula field

In the Data section of the Builder, add a text formula field called "Random ID" to a table. We'll use the Customers table for this example:

Set text formula field to value

  1. Click to edit the Random ID text formula field.
  2. Click in the formula field and enter the random() function, with any number of characters that you want your ID to have, eg. random(7)

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.

  1. On the same Customers table, add a new short text field called ID.
  2. Click to edit the ID short text field.
  3. Click on the "Conditional Rules" tab, and then checkbox "Add conditional rules".
  4. Add a rule:
  • When "ID" "is blank",
  • Value Set "to a record value" "Random ID" :

This way, it will only be set once. Once the ID field value is no longer blank, it will not reset.

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.

Notes & Troubleshooting

Do not use the Random ID field elsewhere in your app since it will change with each record update.

How did we do?

Generate Simple Numeric Barcodes Automatically

Calculate Age in Years from a Birthday