# Auto increment in bubble

**URL:** <https://forum.bubble.io/t/auto-increment-in-bubble/97364>\
**Category:** Database\
**Created:** [June 16, 2020, 6:47am UTC](https://forum.bubble.io/t/auto-increment-in-bubble/97364 "2020-06-16T06:47:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![nurzhan](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/nurzhan/32/64042_2.png) [@nurzhan](https://forum.bubble.io/u/nurzhan)\
**Post date:** [June 16, 2020, 6:47am UTC](https://forum.bubble.io/t/auto-increment-in-bubble/97364/1 "2020-06-16T06:47:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![evanlitttle](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/evanlitttle/32/59264_2.png) [@evanlitttle](https://forum.bubble.io/u/evanlitttle)\
**Post date:** [June 16, 2020, 6:51am UTC](https://forum.bubble.io/t/auto-increment-in-bubble/97364/2 "2020-06-16T06:51:07Z")

</div>

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](https://www.youtube.com/channel/UCPbXMT2lTaJFfMDmLgHhXkA)

---

<div class="post-metadata">

**Author:** ![SeanB](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/seanb/32/169120_2.png) [@SeanB](https://forum.bubble.io/u/SeanB)\
**Post date:** [May 10, 2021, 5:02pm UTC](https://forum.bubble.io/t/auto-increment-in-bubble/97364/3 "2021-05-10T17:02:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tona](https://avatars.discourse-cdn.com/v4/letter/t/c37758/32.png) [@tona](https://forum.bubble.io/u/tona)\
**Post date:** [May 11, 2021, 8:23pm UTC](https://forum.bubble.io/t/auto-increment-in-bubble/97364/4 "2021-05-11T20:23:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aaronsheldon](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/aaronsheldon/32/115965_2.png) [@aaronsheldon](https://forum.bubble.io/u/aaronsheldon)\
**Post date:** [May 12, 2021, 2:04am UTC](https://forum.bubble.io/t/auto-increment-in-bubble/97364/5 "2021-05-12T02:04:02Z")

</div>

Better yet build the increment function into a new _thing_ [trigger](https://manual.bubble.io/core-resources/events/trigger-event). That way you are guareenteed no matter which workflow adds a new _thing_ it will always increment and populate the field.

---

<div class="post-metadata">

**Author:** ![aaronsheldon](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/aaronsheldon/32/115965_2.png) [@aaronsheldon](https://forum.bubble.io/u/aaronsheldon)\
**Post date:** [May 12, 2021, 3:21pm UTC](https://forum.bubble.io/t/auto-increment-in-bubble/97364/6 "2021-05-12T15:21:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ian11](https://avatars.discourse-cdn.com/v4/letter/i/c57346/32.png) [@ian11](https://forum.bubble.io/u/ian11)\
**Post date:** [March 14, 2022, 2:11am UTC](https://forum.bubble.io/t/auto-increment-in-bubble/97364/7 "2022-03-14T02:11:37Z")

</div>

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!!)

---

<div class="post-metadata">

**Author:** ![ian11](https://avatars.discourse-cdn.com/v4/letter/i/c57346/32.png) [@ian11](https://forum.bubble.io/u/ian11)\
**Post date:** [March 14, 2022, 11:32pm UTC](https://forum.bubble.io/t/auto-increment-in-bubble/97364/8 "2022-03-14T23:32:41Z")

</div>

It totally works. 🙂

---

<div class="post-metadata">

**Author:** ![help5](https://avatars.discourse-cdn.com/v4/letter/h/85f322/32.png) [@help5](https://forum.bubble.io/u/help5)\
**Post date:** [December 21, 2022, 10:41pm UTC](https://forum.bubble.io/t/auto-increment-in-bubble/97364/9 "2022-12-21T22:41:09Z")

</div>

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.

 ![Screenshot 2022-12-21 at 5.39.12 PM](https://us1.discourse-cdn.com/bubble/original/3X/4/d/4d33ad1af7039eb9e079f6a9d67661a8e28888ec.png)

---

<div class="post-metadata">

**Author:** ![juanrobles.personal](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@juanrobles.personal](https://forum.bubble.io/u/juanrobles.personal)\
**Post date:** [September 23, 2023, 3:29am UTC](https://forum.bubble.io/t/auto-increment-in-bubble/97364/10 "2023-09-23T03:29:33Z")

</div>

> [@aaronsheldon](#):
>
> RDBMS

Hi Aaron, sounds like a great idea, is it posible you share a bubble diagram with bubble language (new to bubble)

---

<div class="post-metadata">

**Author:** ![willmai](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/willmai/32/206346_2.png) [@willmai](https://forum.bubble.io/u/willmai)\
**Post date:** [October 3, 2024, 11:55pm UTC](https://forum.bubble.io/t/auto-increment-in-bubble/97364/11 "2024-10-03T23:55:02Z")

</div>

Thank you so much, very helpful

---

<div class="post-metadata">

**Author:** ![achen2222](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@achen2222](https://forum.bubble.io/u/achen2222)\
**Post date:** [February 27, 2025, 7:56pm UTC](https://forum.bubble.io/t/auto-increment-in-bubble/97364/12 "2025-02-27T19:56:53Z")

</div>

Just posting an update to this. Someone mentioned database triggers and that really is the best way. The reason is if you create the object in multiple places in your code you always have to remember to increment the number. Other people looking at your code someday may not know all the places where you created the object.

Go to backend workflows (not enabled by default)  
click the empty box to add a backend workflow  
Select General-\>database trigger  
Make a database trigger on the object type, set the only when to original value is empty.

When objects are created the object before change is empty. When objects are deleted, the object after change is empty.

The workflow will only get triggered when objects are created.  
Retrieve the last ID, increment it, set the object after change ID to the new value.

My application has various settings and those are stored in a table. I keep track of the newest object ID in that table.
