Extract Last four digits from a phone no

Good evening,

Hope you are well.

I am looking for some help removing the ‘0.’ from the screenshot please. So it leaves me with just a plain 4 digit number each time. I have tried splitting the text but cannot get it to work as planned. I also tried using the Row ID to generate a random no too, but couldn’t get the result I was looking for.

Perhaps there is a better way for Glide to produce me a random 4 digit code without using precision to 4 decimal places to give me the code in the random no column? Any ideas please?

Thanks in advance.

Employee ID needs to be the last 4 digits of their phone number?

or does it need to be random and unique 4 digit number for each employee?

Either option works, as long as it’s a unique four digits. The latter is preferable please.

You could use the text slice column to get the last 4 of the phone number or a roll dice column with 9999 sides.

Keep in mind there’s only 9999 possible numbers if you take either approach

Alternatively you could use a little bit of JS. Something like this I found from Jeff would work and would be more robust.

return Math.floor(Math.random() * 1e12).toString().padStart(12, '0');

Add a unique value to p1

1 Like

If I am not wrong, roll dice column can’t guarantee unique IDs for each employee correct? @Eric_Penn

Roll dice is not good for unique codes… but neither is using 4 digits or last 4 of phone number :man_shrugging:

I’d go with some JS

1 Like

Thanks all for the feedback. If you were to generate a four or six digit random code how would you go about doing this then? It sounds like the general feedback is that doing it the way I proposed is not ideal? Happy for any better approaches, or is JS the most sensible option here?

Generating a random 4 or 6 digit code is trivial - there are umpteen different ways that can be done.

The critical question is - does it need to be unique?

If it does, then you are limited to 9999 and 999999 codes respectively, and it gets somewhat more complicated, because you need to keep track of the codes that have been assigned.

I suppose it would have to be unique and with only 30 odd employees this will be fine. Staff will clock in and out on a Glide screen on a clock in/out module, but the system needs to know which 4 or 6 digit code relates to which employee when they clock in/out.

If it is easier, I can simply generate a four digit random code myself.

What is the actual purpose of the code?
I assume that your Staff will sign into the App?
If they are signed in, then you have already identified who they are and there should be no reason to use any codes :man_shrugging:

They will not be signed into the app, they will get to work and click on an open glide screen (open to all) with the 4 or 6 code to register their clock in or out. The owner doesn’t want everyone to sign into glide individually or out of glide (I know, obvious solution!).

They would like a simple code to follow their existing operations flow. Hopefully this is enough background.

Okay, I see.

If it’s just 30 odd users, I would be inclined to just manually allocate the codes.

You should be aware though that this is not a very secure solution. The full list of codes and associated user mappings will be loaded onto every user device, and discoverable by anyone with sufficient skills and motivation - including anyone in the world that happens to learn the App URL.

1 Like

Thank you for this. Yes all noted. I appreciate the security concerns and have flagged this already - it would not have been my preferred approach!

1 Like

What if you stored the encrypted codes using sha-256… then when the user is inputting his code run that through sha-256 and compare

Maybe overkill or might be worth looking into