Hi everyone,
I’m currently working on setting up a barcode system in Glideapps for my project, and I could use some assistance with generating the barcode codes in a specific format.
Here’s what I’m aiming for:
Fixed Prefix: 00
Random Alphanumeric Characters: Total length of 7 characters, following the prefix.
For example:
00E5ACAS
00F8B92Z
00A3D4PQ
I’m trying to figure out how to generate the random alphanumeric characters in Glideapps while ensuring that the prefix remains fixed at 00. If anyone has experience with Glideapps and knows how to achieve this, I would greatly appreciate your guidance.
Any advice, suggestions, or examples would be incredibly helpful. Thank you in advance for your assistance!
Best regards,
Daniel
With the double zero, your examples have eight characters, not seven. However, to have a prefix of 00 use the pad text left column.
How hard set are you on having 8 total digits including the 00. Can you explain your use case? Guaranteeing 6 or 7 unique digits is really hard. Especially if you don’t have any reference for existing codes that have been assigned. I can get you something with 10 total digits including the 00 that is much more likely to be unique. If you are willing to go bigger than that, I can do better. If you are hard set on 8 total digits including the 00, then I can do it, but there is a mild chance that you could run into duplicates.
Hey Jeff,
Thank you for your prompt reply and your willingness to assist me with this challenge. I appreciate your concern regarding the uniqueness of the codes.
Regarding your suggestion to use a total of 10 digits including the 00
, unfortunately, due to system limitations and our current setup, we are not open to exploring a 10-digit solution. We need 8 digits for compatibility with our system.
While uniqueness is important, it’s not a strict requirement for our use case. The main objective is to have randomized codes that do not follow a predictable pattern and differ each time they are generated. The 00
padding can also be utilized for this purpose.
With that in mind, I believe the 8-digit solution, even if not entirely unique, would still serve our purpose.
Regarding the use case, this is for our alarm company where we temporarily track parts per install job. So, while uniqueness is important, it’s not a strict requirement, as as soon as the job is done, the codes can be used again. Typically, we have 14 codes in use at any given time. However, if the codes overlap, that’s acceptable to us.
Thank you for your assistance.
Best regards,
Daniel
1 Like
One way to do that is set column values Unique Identifier to user specific column. Next remove the “-“ with a template column. Then text slice 6 characters, pad left 00, and finally uppercase.
But if you want a one column solution … wait for Jeff 
2 Likes
Here is some javascript that should work. I won’t call this unique by any means, but for the use case you explained, I think it should work pretty well with little to no duplicates.
What this does is take the current unix time and applies base 36 encoding, which gives a result of 8 characters with letters and numbers. This gives a result that won’t repeat in our lifetime. However, to fit your requirement, I then truncate the first two letters and replace them with ‘00’. By a very rough estimate, it would probably take days, months, or years (to much brain power to do the math) to ever run into a potential duplicate… and that’s only if you happened to trigger a new code at the exact same millisecond that a previous code was generated. Chopping off the first two characters of the encoded result really throws a wrench into the uniqueness. While I can’t guarantee the codes will always be unique, I think there is little too no chance that you will run into duplicates.
This is essentially an encoded and chopped up version of the number of milliseconds that have accumulated since January 1st 1970. It’s an incrementing number, so it’s somewhat predictable because the beginning of the code will change more slowly, while the end of the code will change rapidly.
function generateUniqueCode() {
// Get current timestamp
const timestamp = new Date().getTime().toString(36).substring(2, 8).toUpperCase();
return '00' + timestamp;
}
return generateUniqueCode();
While the javascript itself does not require any parameters, you’ll still need a parameter to force the code to regenerate. Notice below that I use the current time. Since time in glide updates every 10 second, this generates a new code every 10 seconds. If you need the code to regenerate more rapidly, then I suggest having a flow in your app where you write a unique value or a timestamp to a column whenever you need a new code, and then use that column value as the parameter or an additional parameter in the javascript. This forces the javascript to recalculate and generate a new code. Hope that makes sense.
3 Likes