Alternative to unique IDs (for booking refs for example)

Hello,

I am building a booking app and I’d like each booking to have a booking number.

Any ideas to set it up other than using the unique ID ?

I want something shorter, as a client must be able to spell the booking number to the client service easily.

Thank you !

Calculate random string, put it in a backend to loop and recalculate only if booking link ID already exists

4 Likes

Thanks Chris,

Would you take a few seconds to list the steps to perform this a bit more in details ?

Currently I have it set up like this :

  1. “book” button is clicked
  2. Workflow : Create new booking, and Booking reference = generate random string

Thank you

That’s it, but you’ll then need to check that the random string is unique… and if it’s not, then generate a new one.

Alright, isn’t there any solution to have that checked automatically ?

Why not making them sequential?

Not automatically, no… - that’s what the built in Unique IDs are for (also Slugs are checked automatically for uniqueness, but if they are not then a number is appended to them, so probably not what you want in this case).

When book is clicked trigger a api workflow

Step 1 make changes to a thing calculate random string

Step 2 is to reschedule the same API workflow only if do search for booking link, ID :count is > 1

That will regenerate it until it’s unique just incase you get dupes

2 Likes

Could you just create a field called ‘booking number’, then whenever the booking is created, you cold perform a search in your database for the count of all the existing bookings.

Once the count has been performed, you could +1 to that number - giving it a sequential booking number.

Yep then two people search at the same time and it makes a duplicate :cry:

2 Likes

Thanks Chris, this seems like a great idea ! Appreciate it

I would usually go with something simple like current date/time formatted as yymmddhhmm. You can break it to something like yymmdd-hhmm it looks a little nicer.

It’s simple to setup and it’s understandable.

1 Like

I think this is the way to go since the new WU system will make this kind of searching and comparing extremely expensive and therefore not worth the struggle.

Current timestamp plus a little salt can do the job. Depends on how many users you have and if collusions are likely or not.

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