Top
Systemwalker Runbook Automation Studio User's Guide
Systemwalker

A.1 General JavaScript Functions

You can use the JavaScript functions explained in this section with Java Actions, triggers, Complex Conditional Nodes, and Sequential Loop Nodes.

Note

As numeric values are treated as values of the Number type, you can only use the following range of integers in JavaScript:

  • Minimum: -9007199254740992

  • Maximum : 9007199254740992

Note that the following minimum and maximum values of the Long type are not supported:

  • Minimum: Packages.java.lang.Long.MIN_VALUE

  • Maximum: Packages.java.lang.Long.MAX_VALUE

new Packages.java.util.Date()

For a description, refer to the Javadoc provided with the J2SE Development Kit (JDK).

Date DateAdd(Date or Number date, Number offset, String field)

Returns a JavaScript Date object containing a date and time that is the result of adding the offset to the date

The String field determines the unit of time for the offset. Valid field values are:

Field Value

Description

"ss"

Seconds

"mi"

Minutes

"hh"

Hours

"dd"

Days

Example:

var now = Packages.java.util.Date();
uda.Date = DateAdd (now, 1, "dd");

Note

In the above example, the User Defined Attribute (UDA), Date, is of the DATE type.

If now has the following value:

Tue Jul 01 2006 14:02:59 GMT-0800 (PST)

Then, tomorrow ( DateAdd ( now, 1, "dd" ) ) has the following value:

Wed Jul 02 2006 14:02:59 GMT-0800 (PST)

If date is of the Number type, its value is interpreted in milliseconds since January 1, 1970.

Boolean DateCompare(Date or Number date1, String operator, Date or Number date2)

Compares two Date values, and returns TRUE or FALSE as the result of the comparison

Valid operators are:

Operator

Description

">"

Greater than

"<"

Less than

">="

Greater than or equal to

"<="

Less than or equal to

"=="

Equal to

"!="

Not equal to

Example:

var now = Packages.java.util.Date(); 
var tomorrow = DateAdd (now, 1, "dd"); 
if (DateCompare (now,"<", tomorrow)) ...; //... Executes because DateCompare evaluates to true.

If date1 and date2 are of the Number type, their values are interpreted in milliseconds since January 1, 1970.

Number DateDiff(Date or Number date1, Date or Number date2, String field)

Subtracts date2 from date1, and returns the difference between these date/times in days, hours, minutes, or seconds depending on the field value

Valid field values are:

Field Value

Description

"ss"

Seconds

"mi"

Minutes

"hh"

Hours

"dd"

Days

Example:

var now = Packages.java.util.Date();
var tomorrow = DateAdd (now, 1, "dd"); 
var diff = DateDiff (tomorrow, now, "dd")); //diff has a value of 1.

If date1 and date2 are of the Number type, their values are interpreted in milliseconds since January 1, 1970.

Example:

var date = DateDiff (20000000,10000000,"ss");

BigDecimal DecimalAdd(BigDecimal value1, BigDecimal value2)

Returns a JavaScript BigDecimal object that is the sum of the specified parameters; the result inherits the precision from the parameter with the most significant figures

If you want to assign the result to a UDA, ensure that the UDA is of the BIGDECIMAL type.

If you pass any other data type as a parameter, the function converts the parameter to a BigDecimal value.

Example:

int x = 39;
var z = DecimalAdd ("3.1416",x);

If z is of the BigDecimal type, its value is 42.1416.

Boolean DecimalCompare(BigDecimal value1, String operator, BigDecimal value2)

Compares two BigDecimal values, and returns TRUE or FALSE as the result of the comparison

Valid operators are:

Operator

Description

">"

Greater than

"<"

Less than

">="

Greater than or equal to

"<="

Less than or equal to

"=="

Equal to

"!="

Not equal to

If you want to assign the result to a UDA, ensure that the UDA is of the BIGDECIMAL type.

If you pass any other data type as a parameter, the function converts the parameter to a BigDecimal value.

Example:

var smallDecimal = "1.11";
var largeDecimal = "22.22"; 
if (DecimalCompare (smallDecimal,"<", largeDecimal)) ...; //Executes because DecimalCompare evaluates to true. 

BigDecimal DecimalDivide(BigDecimal value1, BigDecimal value2, Number scale)

Divides value1 by value2, and returns the result of the division

The scale field determines the number of significant digits for rounding. Any number can be used as the scale value; default is 2.

The rounding mode is always to round half up; rounds towards the "nearest neighbor" unless both neighbors are equidistant. In that case, it rounds up.

If you want to assign the result to a UDA, ensure that the UDA is of the BIGDECIMAL type.

If you pass any other data type as a parameter, the function converts the parameter to a BigDecimal value.

BigDecimal DecimalMultiply(BigDecimal value1, BigDecimal value2, Number scale)

Multiplies value1 by value2, and returns the result of the multiplication

The scale field determines the number of significant digits for rounding. Any number can be used as the scale value; default is 2.

The rounding mode is always to round half up; it rounds towards the "nearest neighbor" unless both neighbors are equidistant. In that case, it rounds up.

If you want to assign the result to a UDA, ensure that the UDA is of the BIGDECIMAL type.

If you pass any other data type as a parameter, the function converts the parameter to a BigDecimal value.

BigDecimal DecimalSubtract(BigDecimal value1, BigDecimal value2)

Subtracts value2 from value1, and returns the difference as a BigDecimal object

boolean toBoolean(String or Number value)

Converts value to a JavaScript Boolean

The value can either be a String containing "TRUE" or "FALSE", or a Number containing zero (for TRUE) or non-zero (for FALSE). The function returns TRUE or FALSE depending on the parameter passed. If the value cannot be converted to Boolean, FALSE is returned.

BigDecimal toDecimal(BigDecimal value, Number scale)

Converts value to a BigDecimal object, and returns the result of the conversion to the number of significant figures specified with scale

Any number can be used as the scale value; default is 2.

If you want to assign the result to a UDA, ensure that the UDA is of the BIGDECIMAL type.

If you pass any other data type as a parameter, the function converts the parameter to a BigDecimal value.

Packages.java.lang.Float.parseFloat

For a description, refer to the Javadoc provided with the JDK.

Packages.java.lang.Integer.parseInt

For a description, refer to the Javadoc provided with the JDK.

Packages.java.lang.String.valueOf

For a description, refer to the Javadoc provided with the JDK.

Note

As numeric values are of the Number type in JavaScript, only the following range can be treated as Integer:

  • Minimum value: -9007199254740992

  • Maximum value: 9007199254740992

Note that the following minimum and maximum values of the Long type cannot be used in JavaScript expressions:

  • Minimum value: Packages.java.lang.Long.MIN_VALUE

  • Maximum value: Packages.java.lang.Long.MAX_VALUE