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…
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.
Setup a simple when condition is true workflow (suggested by @emmanuelin 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
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!
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”.
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.
Setup the first action to modify the passed in entry, create the unique ID using Calculate Formula > Generate Random String.
Setup a second action: schedule API workflow with the “only when” parameter running a search for duplicate IDs.
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.
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!