Special JavaScript features

Interrupting execution

From inside the Editor, click the Cancel a running script icon on the toolbar, to interrupt JavaScript execution.

Creating user-defined errors

Use the throw("xx") function to enforce an error and interrupt the execution of the project. For example, to 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”);
)

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 ETL are represented as strings. This may result in unexpected behavior when working with numeric values. 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

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