Unique ID Generation

@Bobby for number type properties, “Maximum” returns the maximum value from all properties in the collection.

Best regards, Victor.

Ok, that’s what I thought.

That could technically return the a duplicate result too then couldnt it?

For what it’s worth ive already found a solution to my problem but if anyone comes back and reads this, just to have some clear info :slight_smile:

My solution was; since I made “username” a unique field i just took the logged in users - username and added a RAND number to it.

Well, if you add +1 to Maximum - how will it return duplicate result? :slight_smile:
I’m not talking about “race” conditions, when 2 users are added at the very same moment of time. Usually this is quite rare case in most of scenarios.

Great that you’ve chosen the solution which suits your needs best!

Best regards, Victor.

Cant the maximum be reduced if the number of users are reduced? Or is this a count of all users that have ever been created?

It’s not a count, it is maximum.
E.g. you have a collection with ID property, ID is numeric.
You add a record and set ID to 999.
You add another record and set ID to 1.
When you use “Count”, you’ll get the value of 2.
When you use “Maximum”, you’ll get the value of 999.

If every time you add a new record, you put ID as Collection → ID → Maximum +1, then you will always have a higher value in a new record.
It works with all collections, not just Users.

There is a slim chance that 2 app users will add records to the collection at the same time. With this you may end with two similar IDs. But again, the chance is quite low.

I’d say that personally I’d go with unique ID generated based on 2 large random numbers :slight_smile:

Best regards, Victor.

1 Like

What do you mean by not allowed?

It works on my app with no issues creating those IDs.

Sorry, not allowed for my application. I can only have alphabetical and numerical characters for what I use the ID for. Adding the date and time field includes things like colons.

If you set a date on a non date field, it will be stored as a number…

No, it still adds the colon as well as hyphens.

image

Even if it’s a numeric field? I’m not in front of my computer but I know that’s how I do it and it’s definitely numeric

So, yeah. I guess if the field is a number field it puts out a number, but has a period in it and that is not a character I can use.

The formula I use is used on a number field.

By multiplying Current Time by 1000000 and using the round function, you end up with an integer with no decimals.

Then adding the random number between 1 and 1000, and you have a unique ID.

The formula works and the result is an integer with no decimals.

2 Likes

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