Generating shorter unique ID for every user

For every user in my user-profile table i want the user to be associated with a “short” 6-8 character unique code ( read as affiliate ID ) which can be used by new users as referral.

a. I initially thought of using the unique username the user registers with to be used for this purpose but i do give an option for the user to change the username in future so this fails
b. i tried to see if the UniqueID generator can be used but this is a very long string and i want something short of 6-8 chars max ( alpha-numeric )
c. Tried to use randbetween function and then wrapping it up with DEC2HEX to generate the string. But i need to to this to a field/cell only when a new user registers and it should remain static once generated for a given user - Struggling with it ( got a GSheets script too which generates this code)

But wondering how to populate this value only when a new user is registered - all the IF , IFBLANK, kind of conditions in sheets are not going though the way i want.

Apparently Glide doesnt have an option of generating random string with length as constraint :frowning:

The amount of search i have done and not yeilded results mean that there might be a simpler way of doing which am not able to figure out in this struggle.

Anyone can help ?

Shiv

I believe an arrayformula with some string manipulations here works best. To keep it 6 characters you can possibly use the first 6 characters of the rowID (using LEFT), last 6 characters of the rowID (using RIGHT) or include the row number in there.

Tell me how you want it to be, I will construct the formula for you.

@ThinhDinh I am fine with the first 6 characters.

But how do i ensure that this column gets populated only when there is a new entry in the users table? The moment we say formulas we are talking about GSheets right and the row ID is generated in GlideTable primarily ( i know we can see this value in GSheets also ).

-Shiv

A few different approaches discussed here:

:exploding_head:

@Darren_Murphy @ThinhDinh

Kind of did a bit of reading and came up with this

={"Code";ARRAYFORMULA(IF(A2:A="","",DEC2HEX(RANDBETWEEN(0, 9999999), 6)))}

Now this generates a 6 digit code

BUT

Its giving same value for all rows - which is bizzare !

And every refresh of the sheet or deletion or addition of row - all the value changes !

I feel some tweak on the above can make it static and unique - ?

Edit: Assume that what i am checking in the Column A is the presence of username in the userprofile
sheet

EDIT2 - Tried the ISBLANK - same behaviour - if i delete or add row then value changes

={"Code";ARRAYFORMULA(IF(ISBLANK(A2:A),"EMPTY",DEC2HEX(RANDBETWEEN(0, 9999999), 6)))}

-Shiv

For your use case I would steer clear of a spreadsheet solution and instead use the Glide computed columns approach that I offered in that other thread. The problem with the spreadsheet solution is that values will change if a row is ever deleted.

With my approach, the values are locked in once they are set. The only downside is that you have to “kick start” it by setting the first value manually.

@Darren_Murphy Yes i get that - i can probably use something like a serial number and then use the forumula you have shared. But this would be a numerical value.

I don’t want it to be a “Number only” and also It would be good if its random than a series for every new user added.

Also the solution you have mentioned also has to be at Sheet level right not Glide table ?

-Shiv

@Darren_Murphy You meant this one ?

Sorry, I was on my mobile just now, so a bit fiddly to provide a direct link.
This is the approach I’m referring to:

This is done purely in Glide - no spreadsheet formulas required. And the same general approach can be used to generate any variation of an alphanumeric code that you like (with the numeric part auto-incrementing). For example, you could have something like:

  • USER001
  • USER002
  • USER003
  • etc…

The “USER” part would be fixed, with the numbers auto-incrementing.

2 Likes

A bit of playing with the formating ( in spreadsheet ) and came up with this UniqueID

Its def not random and but its definitely Unique. Might not be the solution that i wanted or will use. But something easy to achieve for testing purpose on the sandbox.

I think its easy to guess what i have done there :wink:

-Shiv

1 Like

All that i have done is … Sheets > Select Date Column > Format > More formats > More date and time formats

Can reduce it to only YYYYHHMMSS to make it 10char but that would make it too obvious. So played around with jumbling the order of the Y M D H M S to get something not so obvious and usable.

But would continue to look out for better solution if available ( Who knows Glide might introduce a RAND option in the custom column in Glide tables as a Christmas present )

-Shiv

I think i am spending way too much time on this thing today which i could have spent in a better way :wink:

-Shiv