Auto generate a UserID when a user signs up to my app

Hi,
I need help to figure out how to auto generate a unique user id when a user signs up to my app.
I have a user id property for each user, so I’d like each new user to have the previous user id +1.

What I’ve done so far is to attach a ‘create’ custom action on the submit button on the sign-up form referencing the ‘User ID’ property in Users collection to simply ‘+1’…but it’s not worked…and I can’t figure out why…

I don’t have too many options available when amending the ‘User ID’ property, here’s what I see:

I’ve been at this for hours and can’t figure it out…any help would be amazing.

1 Like

Oh, and I did look at this forum topic…but it’s just not worked…

You can’t edit the primary key ID for a record. It’s not like a SQL db where you can reference the id of the record and do math with it.

The best way to accomplish what you’re trying to do is to set the User ID to a function being a random number between a range. So click on magic text icon then hover over functions and use the “RAND” function. Set the range from 0 to 99999999999

2 Likes

Hmmm, didn’t work.
Here’s how I set the custom action:

I created a test user, checked in the collection…there wasn’t anything there :frowning:

Did I do something wrong?
Or miss something out…?

Well you also have 2 separate functions on the same action (Sign user up and Create User). So which one are you doing? If your form “Signs the user up” then you have to set the function immediately after it to “Update” the logged in user because you’ve already created the user in the first function. Even though it runs on the same singular action, the “Sign up” function runs first, then the “Update” function will run.

Ok, that makes sense.

I’ve changed it the custom action to ‘Update’ and added the same random

It didn’t populate the User ID property unfortunately…

Instead of doing it this way, I would set it automatically on the form and remove the update statement altogether.

image

1 Like

What I’ve used that worked for me was to access the maximum ID of a table and add 1 to that. So if there’s no ID, 1 is the result. now there’s only one ID, its 1 and its the maximum, so the next will be 2. If I delete the record with the ID of 1, then 2 is still the maximum and the next will be 3.

Screen Shot 2020-11-11 at 10.12.22 PM

The difference with the RAND option is you will get incremented IDs instead of just random IDs. Also I think with just the RAND option there may be a far out possibility of repetition, though I’m not sure about it, but I know its not easy to set a unique fields Adalo yet.

3 Likes

Great, thanks guys, it worked!
Simple when you know how… lol :slight_smile:

For those coming after who also have this problem, here’s a couple of screenshots of how it’s set up and what you should be looking for.

Create an ‘Automatic Field’ and clicking the magic symbole navigate to Users -> User ID -> Maximum and then add ‘+1’ and you’re done. (obviously you’ll have to create the ‘User ID’ property on your collection.

6 Likes

You can use the random # formula just give it a number like this Rand(1000,9999) if you don’t want/need them to be sequential.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.