Special JavaScript Features

Use the Cancel a running script icon on the editor toolbar to interrupt JavaScript execution.

Creating User-Defined Errors

To enforce an error and interrupt the execution of the project, use the throw("xx") function. For example, to stop execution if the name of a product (PR_NAME) exceeds the length of 20 characters, use:

if (uLength(IN.PR_NAME) > 20) (
      throw(“Product name exceeds maximum length”);
)

Creating User-Defined Functions

You can define functions inside a script and create nested functions. For example, this script results in a value 6 for variable b:

var a = 2;
var b = 20;
b = IncA(a);
// end
function IncA (a)
{
     var b = 3;
     a = IncB(b) + a++;
     return a;
     function IncB(b)
     {
          b = b + 1;
          return b;
     }
}

Converting Datatypes

All variables in Sybase IQ InfoPrimer are represented as strings. If you work with numeric values, this may result in unexpected behavior. You can use the functions parseInt() and parseFloat() to convert a string to an integer or a float, for example:

var a = "123";
var b = "22";

a > b

will return FALSE while

parseInt(a) > parseInt(b)
returns TRUE.

Including Files

To include external files into a script, use the uScriptLoad(“filename”) function. The external file can contain any valid JavaScript constructs, including functions, thus allowing a kind of reusable code, for example:
uScriptLoad("C:\scripts\myfunc.js");
var a = 11;
var b = 2;
var c = 0;
b = gcd(a, b);
// gcd function defined in C:\scripts\myfunc.js