Auto Incremented Field

Hi Fellow Bubblers

I need help with auto incrementing a field.

So i have a field called “Lead ID” in the sales table.
I want it to auto increment at database level.

When creating a new thing and using “Current lead id + 1” it does increment, however does it at the current logged in users level. However i want it to increment at the database level irrespective of the user who create it.

So for example, if I have 0 records in the database then
When 1st User creates 2 records, the Lead id will be 1 and 2
When the 2nd user creates 1 record, the Lead id should be 3
Next when the first user again creates a thing, the Lead id should be 4.

Is this possible to do in bubble?
any crm or ticketing system for example will always create new ticket ids irrespective of the user creating it, they are auto incremented at the database level and not at the user level.

Any suggestions to achieve this are greatly appreciated.

Thanks
Sean

Hi there, @sanjeevscode… set aside the fact that someone is likely going to tell you that you don’t need to generate your own ID’s because things have a Bubble-generated unique ID, you should be able to get the desired result by adding 1 to a count of the leads in your database, assuming multiple leads aren’t going to be created at the “exact” same time (which could result in duplicate ID’s).

Best…
Mike

3 Likes
  1. You don’t need to do this.
  2. For a discussion, see How to achieve Unique, Sequential Numbers Reliably? - #57 by morgan

(Read that post first, then read entire thread. At end, I provide an updated approach. But again your things already have IDs.)

3 Likes

And go read the heck out of the link that Keith provided.

2 Likes

Thanks for the reply Mikeloc.
However like i mentioned it is not incrementing at the database level. It is doing so at the user level.
This is how i am incrementing when creating a new thing:
image
Leadid

Using the above, i see multiple entries with similar lead ids but different created by users.

Infact for each new user when the create a new thing, it starts with 1.

Any suggestions?

Try Search for Propertys:count + 1. If that doesn’t work, check to see if privacy rules are getting in the way of the search returning all of the properties in the database to get the count.

@sanjeevscode go read the thread I pointed to to learn why naive approaches to this will not work.

Thank you Mikeloc, it worked!
It was the privacy rule thing like you correctly mentioned.

Once i sorted that, both yours and my formula works!!

Appreciate your quick responses!

mikelocs suggestion worked for my use case.
Jfyi keith

No it doesn’t, but you’ll learn why eventually. Don’t say I didn’t warn ya.

3 Likes

Happy to hear it worked, but again, you should take the time to read through the great info at the link Keith provided because there is a chance you can get duplicate ID’s by using the count method.

2 Likes

Yes will do.
Thank you both mikeloc and keith.

2 Likes

:rofl:

1 Like

You will 100% get duplicate entries.

2 Likes

That’s such a great old thread though, right, @troy.roberge?

I reread it today and it’s very entertaining. (Though it’s unfortunate that more recent replies there are guilty of making the same mistakes that are fully explained earlier in the thread!)

Keith designing an accounting system: “What’s wrong with verbally telling customers invoice 1660847978224x592797188006293200 is past due?”

2 Likes

I’ve never said one couldn’t have an alternate (shorter, longer, more human-friendly, whatever) ID generated in a different way. But I’d make it unique in a modern way (and, just like Bubble generate it on the client side whenever possible), rather than being based on a count.

(There’s a somewhat hidden feature in List Shifter just for such purposes - “nanoid” operator in Process List!)

I’m also very interested in another unique identifier I ran across recently: Alaska Airlines confirmation codes are short series of alpha characters that almost always “spell something” - not an actual word, but are human-pronounceable and easily memorable. I haven’t figured out how they do that / if it’s from some library, but I’d really like to find out.)

4 Likes

It’s a heavy heavy post lol

1 Like

You really should read the thread @keith pointed out and @mikeloc emphasized.

My humble opinion is that unless you truly really need incremental fields (like an accounting system) there are other ways to have incrementing serials.

I personally would use a current date and time formatted to yymmddhhmms been doing that for my invoices for years.

2 Likes