How to create Nano ID's in Workday Studio
posted
Nano IDs are randomly generated string of characters. Like a smaller Workday ID or UUID. They can be used for generating more friendly reference IDs or maybe a filename suffix to make them unique.
Generating IDs is random, so there is always a small chance that the next ID generated collides with a previously generated ID. This may or may not matter… YMMV. Nano ID CC can help estimate how many IDs you’d need to generate to reach a 1% chance of collision.
The Studio code
// Generate a nano ID
//
alphabet = "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; // Longer Alphabet
alphabet = "23456789abcdefghijkmnopqrstuvwxyz"; // Shorter alphabet
random = new java.security.SecureRandom();
id = "";
foreach (i : [1, 2, 3, 4, 5, 6]) {
id += alphabet.charAt(random.nextInt(alphabet.length()));
}
props["nanoID"] = id;