Creating random unique IDs that do not duplicate

I am trying to store a unique 5 digit identifier to each new Supplier that is added to our database. I have tried a couple of ideas to no avail…

  1. Tried building 2 custom workflows that generate random numbers that loop into each other until a unique number that has been checked against the database is provided. However, this creates a bubble system error which makes sense, as this could eventually become recursive.

  2. Setup a simple when condition is true workflow (suggested by @emmanuel in this thread here) - set to every time - that searches the database for any duplicates and spits out a new number using Calculate RandomString each time… problem is the conditional is running 1 time then stops…

Any ideas or possible better solutions for what I’m trying to accomplish?

P.S. I am testing with just 1 digit so I can find duplicates within 10 attempts or less

3 Likes

After hours/days of smashing forehead into keyboard I have a working solution!

Here is my solution, however, let me know if you can find a cleaner way!

  1. First make sure your backend workflows are enabled in settings. You should now see a new button at the bottom of your pages dropdown called “Backend Workflows”.

  2. Setup a new API endpoint in your backend workflows (expose public endpoint set to “no”). Setup a key to ask for the db entry you’d like to modify.

  3. Setup the first action to modify the passed in entry, create the unique ID using Calculate Formula > Generate Random String.

  4. Setup a second action: schedule API workflow with the “only when” parameter running a search for duplicate IDs.

  5. Back at the workflow when your database entry is first created, set up a schedule API workflow action to pass in the recently created entry.

Depending on how many db entries you have, how many digits/alphanumerics you are assigning and how much time your allowing between scheduled API workflows could bring you quick or very long results… either way… your guaranteed a unique number so long as you haven’t used up all your digits.

Enjoy!

11 Likes

This was super helpful and I finally got it to work! thank you

1 Like

Glad it helped!

Hey Daniel

Thank you for this write-up. Although I definitely learned a few things, I haven’t gotten it to work.

The development environment doesn’t show any errors, but when I activate the API with the button on the live page it first loads very long and then I get this message:
“Sorry, we ran into a temporary bug and can’t complete your request. We’ll fix it as soon as we can; please try again in a bit!”

Any ideas?
I can add screenshots later today if that helps. Thanks in advance!

1 Like

That seems to be a bubble error? I’d try reaching out to support about that.

1 Like

This is super helpful! Thanks for the work you put into figuring this out!

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.