Create A Neat UUID

For any seasoned ColdFusion developer you will be well aware of the CreateUUID() function in ColdFusion that generates a unique string.

Here’s something that I use on a regular basis, just to neaten up the generated string:

<cfset request.thisUUID = Replace(CreateUUID(), "-", "","ALL") />
 
<p><cfoutput>#request.thisUUID#</cfoutput></p>

This then produces a 32 digit string.

Another way of generating a custom uuid is:

<cfset request.dateUUID =
    "#DateFormat(Now(),'YYYYMMDD')##TimeFormat(Now(),'HHMMss')#" />
<cfset request.2digitUUID = RandRange(10,99) />
<cfset request.myUUID = "#request.dateUUID##request.2digitUUID#" />
 
<p><cfoutput>#request.myUUID#</cfoutput></p>

This then produces a 16 digit string. The thing I like about the above example is if it is used for say order id’s then just by looking at the UUID you know when it was made.

No Comments

Sorry comments are closed for this entry.