Forum Academy Marketplace Showcase Pricing Features

Auto increment in bubble

Greetings,

what i am looking for is how to implement order number increment like in MySQL you create id row and tick auto increment checkpoint,

i need it for following, to create order number and each following order would be +1

in programming i would use

var orderNumber = +1

how i should solve this on bubble?

1 Like

Hi Nurzhan,

To solve you will want to go to the data tab: create a data type called order, add a field to that data type called “order no.” and set this field type to be a number.

Now in the workflow section when you create a new order, define a field order no. = insert dynamic data

do a search for orders:count + 1

This will ensure the order count gradually increases by 1

Hope that helps!

For more tutorials visit:
https://www.youtube.com/channel/UCPbXMT2lTaJFfMDmLgHhXkA

7 Likes

Thank you for this tip, @evanlitttle – this is just what I was looking for. Basically instead of a completely random string, I needed an auto-incremented, yet unique, number series and this solution helps get that.

However, while I was thinking about this further, I’m envisioning a scenario wherein if items are deleted from the database, for whatever reason, then this approach will generate conflicting numbers since it’s based on count. For e.g. if I have 14 items in my database, then adding a new product gives me products:count + 1 = Product ID = 15. But if I end up deleting a product from my database table (from somewhere in the middle of the table), then I’m back to having a total count of 14, and the next Product I’ll add will be assigned the number 15. Is there a workaround to this particular scenario using the approach you mentioned?

Thanks a ton once again.

1 Like

Some options to do this:

  1. You can create a new data type with a number field that doesn’t get deleted and gets updated every time you add a new product.
  2. Create a number field on the product data type to track the number, then update the last product every time you add a new product or delete a product. Example, if the field is called ‘atn(all-time number)’, and you currently have 10 products, then you add item 11. Search for the last product and increase atn by 1. In case you delete item 11, search for the last product(product 10), increase atn by 1 again, to make it 11.
  3. Don’t truly delete a product, but create a field that tracks active products. So deleting the product workflow would not delete it but make it inactive.

If you think you’ll have a large amount of products, storage could eventually be an issue for option 3. Option 1 could be a little bit easier to keep track of storage-wise. You could always start from option 3 and go to any other option at any point. Option 2 would require you to configure your search in a way to grab the last known atn.

Better yet build the increment function into a new thing trigger. That way you are guareenteed no matter which workflow adds a new thing it will always increment and populate the field.

2 Likes

The old school RDBMS way of doing this is to have a system thing containing high water marks, say System High Water Mark. This thing contains at least two fields:

  1. Referenced Things Name which contains the name of the thing that you want to track the high water mark of
  2. So Far which contains a number tracking the high water mark so far of the thing.
    Every time you add a new thing to the things you are auto-incrementing you look up the So Far by NAME of the thing and add one to it. Then store that value both in the increment field of the thing you are creating and in So Far.

Clear as mud right?

1 Like

I found this because I was looking to solve the same problem.

The way I am going to work on it is to create an order number field in my order data and add the first order manually.

Then when the second order comes in, I am going to look up the last order’s order number +1 and write it to the order number field.

In this way if the data behind it gets deleted it shouldn’t mess things up.

In my case, because the “order number” is also specific the customer, I’ll set a workflow up when the customer is created to hardcode their first order number and subsequent orders will follow the above.

I haven’t built this, and I’ve been using bubble for like, 13 hours lol. So if this seems like it won’t work just let me know (or… if I find out it won’t work… I’ll be back!!)

It totally works. :slight_smile:

does this still work? I am a total bubble noobe, and I can’t figure out how to insert dynamic data or where to do that. Am I in the right area here in the attached image.