Creating GUID using Custom Script

Document created by tommy_conway636242 Employee on May 10, 2017Last modified by chris_stevens on May 11, 2017
Version 4Show Document
  • View in full screen mode

Below is a script that can be used to generate a GUID. This is to be used in a custom script, map shape function, as this is JavaScript. 


function getGuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
var guid = getGuid();


This results in a GUID in the below format:


Below is a picture of editing the script in the map function.



The solution above uses Math.random() for brevity, however Math.random() is not guaranteed to be a high-quality Random Number Generator (RNG). Because this is not guaranteed, you will want to include some sort of decision making in the process to make sure the GUID is truly unique. The below image is a sample of one of those methods. This may not work for each use case, but is something that can be used for smaller data amounts. 



The above process loads a document on branch 1, that has GUIDs that have already been created and are being used. The data process shape splits the document into individual GUID's and adds them to a cache shape. On branch 2, the process generates a GUID in the map shape and adds it to the profile. The decision shape looks up the GUIDs that have been cached already and makes sure the GUID that was created in the map shape is not the same as one that is already in use. If it is unique, it goes down the true path, if it is not unique, it goes down the false path, which is looped to run the map again and generate a new GUID.

3 people found this helpful