Custom Functions - Search / Contains

| No Comments | No TrackBacks
There is no string contains function by default, but one can be added using the code below.





Code:

var n=InputString.indexOf("in field 'Serial number' is not found in relating table 'Serial numbers'.");

if(n != -1)
{
    return 'Serial number is not found';
}


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('');