Assigning the lowest available number in a numeric range

I want to assign every “Registration” the lowest number within a given range. Let’s say I have a number range set from 100-199. When a new Registration is created, I need a workflow that finds the lowest number from 1-99 that is not assigned to another registration. How would you handle this working with the field type “Numeric Range” ?

Bubble doesn’t allow you to search or iterate through individual values in a numeric range. So, to assign the lowest available number efficiently, I recommend pre-generating the numbers.

Start by creating a new data type called RegistrationNumber with the following fields:

  • number (Number)
  • is_assigned (Yes/No)

Then, populate this data type with numbers from 100 to 199. You can speed up this step by uploading a CSV file.

When a new registration is created, use a workflow to find the lowest unassigned number:

  • Do a search for RegistrationNumber where is_assigned = no
  • Sort the results by number in ascending order
  • Use :first item to get the lowest available number

Assign that number to the new registration, and don’t forget to update the is_assigned field in the RegistrationNumber entry to yes.

Thanks for taking the time to send this @igor.le.nascimento !

The range 100 to 199 is a simple example range and this will be done numerous times a month, with potentially thousands of Registrations. So some ranges might be 1-499 for example. I’m thinking that creating something over and over is going to take up more work units than somehow running a workflow that checks if the number is available and is in range… and if false, will check the number+1. Trying to figure out the best workflow that is cost effective and intuitive.

I do understand the process you are mentioning and I believe it will work great. However, do you think it would end up costing a lot of money with “creating” so many things over and over?

Hy @runthis :waving_hand:

You can convert this range in a list of numbers, subtract the users number from this first list and get the minimun value.

Take a look:

Editor here