I need a way to generate a unique ID number. I was trying to do this with the randomizer, but I cannot get it to work consistently.
The app does not have any real users yet, so I can start with 1. Is there a way that anyone can think of to assign the next number to a user when signing up?
Of course there will be a chance that you could get the same number.
For instance, if you use RAND(0,999999) the chance of the second number being like the 1st one is one of a million. If you add three more 9s it will decrease to one of a billion.
For the further numbers the probability will increase, of courseā¦ but not much
If you want to be on the safe side you can combine RAND with a Current Time formatted as āNoneā (for text IDs). The probability of 2 users registering at exact same time and getting exact same random number is pretty low
Also, as good as time idea sounded, it adds some other characters into the mix that arent allowed such as a colon and dash.
I think I found a solution though. Since iāve made the app in a way that usernames are unique, iāll couple that with the rand function and that should do it.
1 you can add a random number to a date-time and youāll get a unique number e.g. datetime+3 digit random number
2 if you donāt need to reference the ID immediately you can use integromat to watch for new records and then update an ID field with the actual Adalo ID.
I always use 2 if I donāt need to access the ID immediately after user creation. But 1 should give you a unique ID each time.
Isnāt it possible to simply use a formula in the database to add a +1 to the user ID column? Number the first user 00001, and let the formula take over after that?
So if I understand you correctly, you use the all users count +1.
That could work, but what if a user deletes their account? Then someone can technically grab that same number, it may even start a chain reaction of duplicate numbers if a user deletes.
I use this formula when the user registers to assign them an ID:
Current time is already a unique value as it changes every second, by you could have the case that two or more users click on register on the exact second. Thatās why I added the random function between 1 and 1,000. That significantly reduces the probability that two users will have the same ID.
When user delete user record, maybe update all the information of the user to "deleted userā, but not removing the record. So, the userID by count may still work.
Deleting the record altogether will require deletion of all related records in other collectionsļ¼tables).
One may devise a function/formula to get a unique ID, but I just find it even more complicated.
Just my 2 cents. Cheers.
If someone prefers to use incrementing IDs, please keep in mind, that you need to use ID ā Maximum +1 as a new ID, not Count.
Example reason not to use count: you create 10 users, 11th one will get ID=11. You delete 5 users, 6 are left. The 12th one will get ID=7.
The āfunnyā part in all this topic is that Adalo already has unique IDs for every record in every collection. For some reason this information isnāt available in the app builder (however it is easily accessible via API). So we are kind of reinventing the wheel here.
It has been requested several times to make these IDs publicly available. I did this as well, please feel free to upvote: Make unique record IDs publicly available | Voters | Adalo