Custom Functions - Generate GUID and NULL Return

| No TrackBacks
I had a could things I needed for a project that weren't standard in the functions list. I googled around and snagged some java script code that works just fine and made a custom function that I reuse across many of my projects. Here is a quick tutorial and example of code.

-Asa

1. Create a new custom function.

CustomFunctionMenu.JPG





















2. Give the custom function a name. There is no input parameter required

CustomFunctionParameters.JPG






























3. Enter the code as shown below, which will return a valid guid to any string variable.

CustomFunction.JPG






























Code:

var s = [], itoh = '0123456789ABCDEF';

  for (var i = 0; i <36; i++) s[i] = Math.floor(Math.random()*0x10);

  s[14] = 4;
  s[19] = (s[19] & 0x3) | 0x8;

  for (var i = 0; i <36; i++) s[i] = itoh[s[i]];

  s[8] = s[13] = s[18] = s[23] = '-';

  return s.join('');



No TrackBacks

TrackBack URL: http://asaiam.com/mt-tb.cgi/13

About this Entry

This page contains a single entry by AsA published on October 9, 2010 1:14 AM.

Find recent content on the main index or look in the archives to find all content.

Categories

Pages

Powered by Movable Type 5.01