From inside the Editor, click the Interrupt button to interrupt a JavaScript execution.
Using the throw("xx") function, an error can be enforced to interrupt the execution of the project. For example, stop execution if the name of a product (PR_NAME) exceeds the length of 20 characters:
if (uLength(IN.PR_NAME) > 20) ( throw(“Product name exceeds maximum length”); )
Functions can be defined inside a script and functions can be nested. For example, the following 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; } }
All variables in the Sybase IQ ETL are represented as strings. This may result in unexpected behavior when working with numeric values. The functions parseInt() and parseFloat() can be used 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.
Use the uScriptLoad(“filename”) function to include external files into a script. 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