Using Structured Data Types

A range of factory methods are supplied for creating instances of structured data types within scripts. You use these methods for creating objects and performing operations on objects of specific types in scripts.

These methods are listed in ’ScriptUtil’ in ’Script Functions’ in the Business Data Services Guide.

The version of JavaScript used by BPM scripting does not support the new keyword; instead, you must create new objects using these factory methods.

For example, the following line could be used to initialize a datetime field called dtYearEnd, using one of the methods described in ’Script Functions’ in the Business Data Services Guide:

dtYearEnd = DateTimeUtil.createDatetime("2010-12-31T23:59:59");

The normal JavaScript arithmetic operators (such as +, -, *, /) are not supported for use with variables containing objects of these types. Instead, you must use the method listed in ScriptUtil in ’Script Functions’ in the Business Data Services Guide for the underlying Java type of the object.

Note: Fields of the types listed in the table below, such as Intger(subtype:Fixed) and Decimal(subtype:Fixed) types have to be manipulated in this way; but the basic Integer(subtype:Signed) and Decimal(subtype:Floating Point) fields can be manipulated using the standard arithmetic operators.

The following table gives a summary of the types affected, with the factory methods used and the underlying Java types:

BPM Object Type BPM Sub-type Factory Method to Create Underlying Java Type
Date   DateTimeUtil.createDate XMLGregorianCalendar
Time   DateTimeUtil.createTime XMLGregorianCalendar
Datetime   DateTimeUtil.createDatetime XMLGregorianCalendar
Datetimetz   DateTimeUtil.createDatetimetz XMLGregorianCalendar
Duration   DateTimeUtil.createDuration Duration
Integer Fixed ScriptUtil.createBigInteger BigInteger
Decimal Fixed ScriptUtil.createBigDecimal BigDecimal

For example if you wanted to assign another variable, dtNextYearStart, to be one second later than the dtYearEnd field that was assigned in the example above, you could add one second to the previous field, like this:

dtNextYearStart = ScriptUtil.copy(dtYearEnd);

dtNextYearStart.add(DateTimeUtil.createDuration("PT1S"));

or

dtNextYearStart = DateTimeUtil.createDatetime(dtYearEnd);

dtNextYearStart.add(DateTimeUtil.createDuration("PT1S"));

Care must be taken as the add() method on the XMLGregorianCalendar updates the object, and does not return a value.