I had that discussion sometime ago with Victor, cannot find the thread now though, yes, it is definitely recommended that you use MAX instead of COUNT, but this has a flaw still (Which we both failed to see at that time), which could be very rare to happen but that messes up everything (Or let me know does not make sense, it’s Sunday, I am braindead ):
I have 8 Users currently, let’s imagine I delete USER 5:
We still have max USERS 8, so the next ID should be 9
But if I delete the highest number user (8 also in this case), in this scenario now I have 6 users, the max number will be in this case 7, so your next user would be again 8, which will not match the “internal Adalo id”. so the 9 User on this case would become the 8, the 10 the 9, and the logic would be destroyed.
The easiest way for now, but will consume 1 extra action, is to create a “control collection” that will add a record (just like a 1 or whatever you want), that when you add a record, you also add a record in that collection, so if then a record is deleted from the original, it will not be deleted from this “control collection” and you can always use that count. If you want to track all collections, you could do the following:
Let’s say you have 3 collections and want to have all IDs in all collections:
So we have this scenario:
- Collection 1
- Collection 2
- Collection 3
- Control Collection
When you add a record to collection 1, you add also to control as “Collection 1”, if you add for the 2 you add in the control as “Collection 2”, so you can keep record of how many records existed already for each collection.
You add an extra action to add also record to “control collection”, downside is that it needs an extra action:
How to calculate (For the new user, you would just use “current count” + 1)
Hope it makes all sense
I also have an API for this which is more bullet proof, I am building a process specifically for ID, if you and everyone wants to test, just drop me a DM with the EMAIL, for me to send the API for testing.