Forum Academy Marketplace Showcase Pricing Features

Plus 1 to Database?

Brand new to Bubble can anynone please explain to me how to add +1 everytime someone signs up, like an assigned number, first user is 1 2nd user is 2 and so on ?

1 Like
  1. Create a new custom type in your data base to keep track of this number. There will only be one record in this table, and it only needs one field (type of content is number).

  2. When the User signs up, you’ll first find this record (Do a search for Number of Users:first item), and increment the Number field by one.

  3. Then, update the User’s Number field to be the result of the first step.

Here’s a demo you can look at to see how I accomplished this: Sanscodedemo | Bubble Editor

This approach will ensure that even if Users are removed from the database, the number from the other custom type table will still maintain the most up-to-date count of Users that have ever signed up to the app.

Hope this helps!

Dude you’re Awesome!! i really appreciate your help, it makes a ton of sense but when i compare workflows im pretty sure i copied to the T, it doesn’t seem to update the number in the database? when i run the debugger theres a portion that says "create if the thing doesnt exist and it says : no
is that where i went wrong? do you know how i could fix this? But thank you so much John

1 Like

If you really want to do this, @john32 's approach is great.

However, from experience, I’d recommend against relying on your DB to store the rank of users. When you delete a user, you’ll have inconsistencies in your database unless you go back and edit the rank of each user.

If you’re trying to rank users in a repeating group, use the search and sort function to display them in order.

Can you confirm you have one record in the Number of Users table (or whatever you’ve named this table) and the number field is either blank or 0 when you run this action?

ohh i see i needed to create 1 first? its working now thank you ! would i be able to ask you by chance how i could combat the occurrence of users signing up at the same time and receiving the same number?

That is a great question, and I honestly don’t have an immediate answer!

I suppose you could test this theory by having a few tabs open on a variety of devices around you, pre-fill the form, and press the Submit button at the same time (or as close to the same time as you can) and see what the results are.

If you notice everyone has their own number and the sequence isn’t broken, test it a few more times and see if you can break it. If it does break and two Users are given the same number, then we might need to try another approach.

Only one way to find out!

Yes if someone creates a user at the exact same time you could run into a duplicate user number. The time frame where two people would have to be doing this is probably a tiny window but it’s still possible.

I’ve thought about the idea of generating a random number on the spot, then just having it check if it’s used already, then either keeping it or rolling the number again. Just a concept don’t know how I would even do it.

Create the incremental workflow as a backend API then on the front end; schedule that backend workflow with current date and time.

That backend workflow will first increment your “counter” data then update the new user’s assigned number.

Since backend workflows will not trigger at the same time you can be sure that there will not be duplicates.

Is that confirmed that backend workflows wouldn’t schedule at the same time? Or at least that specific workflow won’t schedule at the same time? I supposed one could schedule, then while that one is running another one is scheduled, but somehow the 2nd one would have to finish first for there to be an issue…

Also really helpful when running it in the backend, I just needed to implement something like this and when I had it “Do a search for” on the client side the privacy rules didn’t allow it to find any other users, so the customer # was always 1. By running it in the backend I could check “ignore privacy rules” and it can iterate the number.

Haven’t read through everything in detail, but it seems a bit of a convoluted way to do a very simple thing.

Each entry is given a ‘created date’, so you can always rank users by the created date and if you need to get get a count, then do a search for users and use the operator :count at the end to pull the count.

If you want to return a certain user via their rank (say the 100th user) then do a search for user, sort by created date earliest to latest and then return item# whatever it is you want.

As others have noted above, there’s really no reason to do what you’re trying to do. However, if one were to desire to create some sort of sequential serial number for something, here is the correct way in bubble. This reply summarizes the solution, but the entire thread is interesting if you’d like to understand all aspects of this issue:

1 Like