Forum Academy Marketplace Showcase Pricing Features

Generate Number with no duplicates

If I needed to create a unique numerical code for an item, what would be the best way to go about doing that without doing a search for every time a new number is generated?

I thought about generating a list using another service then importing the list. The only issue being if I run out of codes I need to generate more codes excluding the ones already created.

Any ideas?

What are the codes used for, can it be alphanumeric, and can it be sequential or follow a pattern?

Non-sequential numeric redemption codes.

How about alphanumeric strings that are at least a certain length using Bubble’s “Generate random string” under “Calculate formula”? Before the string is allowed to be used, check if it was already stored in the database.

Bubble uses the same number when you generate a random string on the same page correct?

Example
Create New Item
number = Calculate random string

Only when search for items item’s number doeskin contain calculate random string

This way I can do it all in one event?

EDIT: After some testing it seems this is true, as long as the generation is in the same workflow the number remains the same.

To get around the same Random String in the same workflow, I use a Custom Event that gets triggered when there is a duplicate.

In the Custom Event I do another Random String generation.
I noticed when I tested this that Bubble does have a preference for specific values when it randomly generates, so in the ‘Custom Event - Recalculate’ I made the string 1 value longer to try and reduce that chance it generates a duplicate. Although not 100% foolproof

Curious to hear how others have set it up

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