# Generating shorter unique ID for every user

**URL:** <https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389>\
**Category:** Ask for Help\
**Created:** [May 29, 2021, 10:05am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389 "2021-05-29T10:05:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shiv](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/shiv/32/25831_2.png) [@Shiv](https://community.glideapps.com/u/Shiv)\
**Post date:** [May 29, 2021, 10:05am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/1 "2021-05-29T10:05:33Z")

</div>

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 ☹

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

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [May 29, 2021, 10:13am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/2 "2021-05-29T10:13:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Shiv](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/shiv/32/25831_2.png) [@Shiv](https://community.glideapps.com/u/Shiv)\
**Post date:** [May 29, 2021, 10:19am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/3 "2021-05-29T10:19:25Z")

</div>

> [@ThinhDinh](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [May 29, 2021, 10:21am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/4 "2021-05-29T10:21:21Z")

</div>

A few different approaches discussed here:

> [@Auto Numbering](https://community.glideapps.com/t/auto-numbering/20355):
>
> How to setting auto numbering that appear with a new order submit by a form button? Example, i have 3 form submitted. i need the first submitted form showing: 0001 - “form result; …” 0002 - “form result; …” 0003 - “form result; …” those 0001,0002,0003 auto generate by data backend.

---

<div class="post-metadata">

**Author:** ![Shiv](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/shiv/32/25831_2.png) [@Shiv](https://community.glideapps.com/u/Shiv)\
**Post date:** [May 29, 2021, 10:39am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/5 "2021-05-29T10:39:17Z")

</div>

> [@Darren\_Murphy](#):
>
> A few different approaches discussed here:

🤯

---

<div class="post-metadata">

**Author:** ![Shiv](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/shiv/32/25831_2.png) [@Shiv](https://community.glideapps.com/u/Shiv)\
**Post date:** [May 29, 2021, 11:07am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/6 "2021-05-29T11:07:34Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [May 29, 2021, 11:19am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/7 "2021-05-29T11:19:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Shiv](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/shiv/32/25831_2.png) [@Shiv](https://community.glideapps.com/u/Shiv)\
**Post date:** [May 29, 2021, 11:24am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/8 "2021-05-29T11:24:59Z")

</div>

> [@Darren\_Murphy](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![Shiv](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/shiv/32/25831_2.png) [@Shiv](https://community.glideapps.com/u/Shiv)\
**Post date:** [May 29, 2021, 11:29am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/9 "2021-05-29T11:29:11Z")

</div>

@Darren_Murphy You meant this one ?

> [@Auto Numbering](https://community.glideapps.com/t/auto-numbering/20355/12):
>
> Here is how I would do it: “Padding” is just a simple ITE… So putting all that together, 4 columns required: Rollup to determine the current max order ID Math column to increment that by 1 ITE column to determine how many zeros required for padding Template column to join 2 & 3

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [May 29, 2021, 11:33am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/10 "2021-05-29T11:33:11Z")

</div>

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:

> [@Auto Numbering](https://community.glideapps.com/t/auto-numbering/20355/12):
>
> Here is how I would do it: “Padding” is just a simple ITE… So putting all that together, 4 columns required: Rollup to determine the current max order ID Math column to increment that by 1 ITE column to determine how many zeros required for padding Template column to join 2 & 3

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.

---

<div class="post-metadata">

**Author:** ![Shiv](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/shiv/32/25831_2.png) [@Shiv](https://community.glideapps.com/u/Shiv)\
**Post date:** [May 29, 2021, 12:13pm UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/11 "2021-05-29T12:13:20Z")

</div>

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.

 ![Screenshot 2021-05-29 at 5.40.09 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/f/9/f913b6beaa364e487b94fcc553621d56ca5b097d.png)

I think its easy to guess what i have done there 😉

-Shiv

---

<div class="post-metadata">

**Author:** ![Shiv](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/shiv/32/25831_2.png) [@Shiv](https://community.glideapps.com/u/Shiv)\
**Post date:** [May 29, 2021, 12:32pm UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/12 "2021-05-29T12:32:49Z")

</div>

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

 ![Screenshot 2021-05-29 at 5.58.55 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/a/0a2d0310c5659fb1f4d3c77164e31901e3774bdb.png)

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

---

<div class="post-metadata">

**Author:** ![Shiv](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/shiv/32/25831_2.png) [@Shiv](https://community.glideapps.com/u/Shiv)\
**Post date:** [May 29, 2021, 12:55pm UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/13 "2021-05-29T12:55:50Z")

</div>

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

 ![Screenshot 2021-05-29 at 6.24.41 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/a/5acfc7965e002b3069942f4f313c44a268c817ae.png)

-Shiv

---

<div class="post-metadata">

**Author:** ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)\
**Post date:** [March 23, 2022, 2:50am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/14 "2022-03-23T02:50:54Z")

</div>

Hi,

I am looking for the generator random number for Barcode as well .

So you are using the formula in Google Sheet isn’t?  
Can I know, is there any delayed ?

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [March 24, 2022, 12:20am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/15 "2022-03-24T00:20:13Z")

</div>

1/Does it need to be in the Google Sheet?

2/What type of information do you want to have in the barcode?

---

<div class="post-metadata">

**Author:** ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)\
**Post date:** [March 24, 2022, 12:52am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/16 "2022-03-24T00:52:13Z")

</div>

1. Yes, so the last option is going to use the google sheet formula.

2. Only unique 13 numbers .

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [March 24, 2022, 12:53am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/17 "2022-03-24T00:53:30Z")

</div>

I imagine if you have it sequentially then it can be an arrayformula, else you might have to find an external service or write some JS.

---

<div class="post-metadata">

**Author:** ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)\
**Post date:** [March 24, 2022, 12:59am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/18 "2022-03-24T00:59:32Z")

</div>

I see, so i’m going to use this formula.

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/f/afa57cdf65e71c45b6f96b69c3904d7a18f6aeb3.png)

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [March 24, 2022, 1:10am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/19 "2022-03-24T01:10:19Z")

</div>

So if you delete a row, then the numbers in all the rows below it will change. Does that matter?

---

<div class="post-metadata">

**Author:** ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)\
**Post date:** [March 24, 2022, 1:11am UTC](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389/20 "2022-03-24T01:11:49Z")

</div>

OOOOOOOOOO. Yes its a problem. ooo ooo yes yes its cannot be.

[Next page](https://community.glideapps.com/t/generating-shorter-unique-id-for-every-user/27389.md?page=2)
