Scripting

There are some changes to scripting in version 5.x, for example, process data fields are now wrapped in a data object and factory methods have changed. Some differences are automatically fixed for you when you import your projects for the first time. Depending on the complexity and nature of your scripts, you may need to fix some scripts manually by addressing the problems markers raised on those scripts.

Retrieving and Setting Process Relevant Data
At run-time, instances of BOM classes are created to represent particular instances of the generic BOM class. These instances are referred to as Business Objects. You can retrieve and set business object attributes, using business data scripting. For example, in pre-version 5.x, you could have the following:
var custName = customerInstance.name;
and you could set the value of the Name business object property as follows:
customerInstance.name = "Clint Hill";
In version 5.x, process relevant data are now wrapped in a data object. To set the same value of the Name process parameter or data field property, you must now do the following:
data.customerInstance.name = "Clint Hill";
Business Object Creation by Factory
Note: This applies to server-side scripting only. Factory usage in client-side scripting in pre-version 5.x is the same as version 5.x.
Business Objects are created by factories. There is a factory method for each class within the BOM (for example, createCustomer, createOrder, and so on). For example, in pre-version 5.x, you could have the following:
com_example_ordermodel_Factory.createOrder()
In version 5.x all BOM factory methods are accessed via a single factory object. To use the same factory method in version 5.x, you must now do the following:
factory.com_example_ordermodel.createOrder()

Important note: You can assign the values of two BOM attributes to the same BOM class instance object. In this situation, changes are made by reference, and the changes are reflected in both places. However, once the script is complete, the data are saved and that single value is stored and, thereafter, behaves as two independent objects. This differs from the behavior in pre-version 5.x, where a business object instance can only be contained by a single container at any given instant.

Working with Enumerated Types (ENUM)

Note: This applies to server-side scripting only. In client-side scripting, enumerated types are handled in version 5.x in the same way they were handled in pre-version 5.x.

If you want to categorize objects as different types, instead of using a number or a free format string, you can use an Enumerated Type (ENUM). In pre-version 5.x, you could use unqualified names to define ENUMs in scripts. In version 5.x, this is no longer supported. You must use a fully qualified name (qualified by the package name) for the enumerations in the script. The qualified name of enumerations to be used in scripts is similar to the factory names, with the qualified name formatted to replace dot '.' by '_' an underscore character.

Secondly, the fully qualified name must now be wrapped in a pkg object. For example:
com_example_shared_ColorEnum.RED
becomes
pkg.com_example_shared_ColorEnum.RED

Case Data Access Methods

Prior to TIBCO BPM Enterprise version 5.x, specific JavaScript classes were dynamically generated to handle specific BOM case classes. TIBCO BPM Enterprise version 5.x has been changed to provide a statically defined (that is, it is always there) JavaScript class that is used for all case classes, where the case class is identified in the method parameters using its fully qualified name (that is, "<bom_package_id>.<case_class_name>".

Upon migration from pre-version 5.0, scripts are automatically changed to use the equivalent new method, assuming there is an equivalent method, and that the referenced Business Data projects have been imported.

ScriptUtility

ScriptUtil provided methods to create various types of object, to modify Duration objects, and to serialize business objects into or deserialize them from their XML representation in pre-version 5.x. These are no longer provided. ScriptUtility should now only be use for copying objects. See ScriptUtil for more information.

Some Script Utilities No Longer Supported

The following script utilities are no longer supported:
  • DateTimeUtil. These methods were used to create date, time and date-time objects of the types used in pre-version 5.x.
  • DataUtil. DataUtil provided a single method that allowed you to create a List object for use in scripting in pre-version 5.x.

Regular Expression Patterns for Text Fields No Longer Supported

In pre-version 5.x, when defining a Primitive Type, text fields could be constrained to match certain patterns. Regular expression patterns are no longer supported.

List Objects No Longer Supported

In pre-version 5.x a process data field specified as an array could refer to multiple instances of a business object. Similarly, a BOM class attribute could refer to multiple instances of a business object. Multiple instances of business objects used to be handled using a List object. List objects are no longer supported. In version 5.x, you must use JavaScript Arrays instead.

WorkManagerFactory and Process Classes

WorkManagerFactory and Process classes have the following changes:
  • WorkManagerFactory is renamed as workManager.
  • workManager and process objects are now wrapped in a bpm object.
Example 1
var theOfferSet = WorkManagerFactory.getWorkItem().getWorkItemOffers();
becomes
var theOfferSet = bpm.workManager.getWorkItem().getWorkItemOffers();
Example 2
var myActivityLoopIndex = Process.getActivityLoopIndex();
becomes
var myActivityLoopIndex = bpm.process.getActivityLoopIndex();