Forum Academy Marketplace Showcase Pricing Features

Sequential numbers

I am having difficulties creating sequential numbers. I’ve read the post on the forum but still not got it.

Users can create an invoice, I need to assign a new invoice number for each invoice created by each user. I’d like a users first invoice to be 00001 and then go up by 1 each new invoice.

Can anyone help with this?

@darren.james7518

First four characters make them texts and the ending one a number. For every new invoice add +1

1 Like

It can be done with a simple workflow. First calculate the number. Then transform the number into text. Use conditionals - if number of characters is (for instance) 2 than concatenate “000” with the number in the text data type. You will have 4 steps in the workflow with the conditionals that are true for either 1 digit, 2 digits, 3 digits or 4. The five digits doesn’t need to add zeros.

2 Likes

If a user has 1000 invoices, will the first four text numbers increase correctly? Why shouldn’t they all be numbers?

Thank you. How do I calculate the number? Also, why should we transform to text? Doesn’t Bubble handle numbers correctly?

Also, why should we transform to text? Doesn’t Bubble handle numbers correctly?

“00001” is not a number (at least not in the mathematical/quantitative sense, which is how Bubble, and other programming languages, define a number).

The number here is simply “1” - whether you stick 4 zeros in front of it, or a million zeros, the number is still just 1, so if you use a Number type in your Bubble datatype that’s how it will be stored (as you’d expect, and as it should be). Just 1.

So if you want to store “00001” it therefore has to be a text, which just happens to contain numerical digits.

So, as other users have stated above, you first need to calculate the new number for your invoice (either do a count of existing ones and add 1, or find the most recent one, convert it to a number, then add 1).

(Potential duplication issues due to race conditions aside), that will give you the actual ‘Number’ for the invoice (i.e. if there were 247 previous invoices, the new one will be numbered 248).

But if you want to store that as 00248 then you’ll need to add the preceding zeros (as text) and convert the number to a text, then save it in the ‘text’ field of your database (you could save it as both a text AND a number to avoiding having to convert it to a number in future, for example when sorting or searching for it).

You’ll need to use conditional actions in a workflow, based on the number of digits in the actual Number, to determine how many preceding zeros to add to the ‘text’ invoice number field.

Thank you @adam for the clear explanation.

Ok, thank you guys, I think I get it now. Appreciate the help as always :slight_smile:

The reason is that number 0001 doesn’t exist. It’s not a number. If you want easy fix here’s the thought I just had. Maybe the first invoice number should be “1,00001”. The next one “+ 0,00001” and so on. In the design DISPLAY everything after the “,”(comma). This might help. Not sure though. Give it a try and let me know, please :slight_smile:

1 Like

That seems like a neat idea, thanks I will try that!

1 Like