Create an Instance of a Class

You can create a new Business Object directly.

Taking the example of the Person/Customer/Employee BOM:

In order to create an customer instance, we first need a data field to hold the instance. This is done by creating a new Data Field in a process, and setting the Type to be an External Reference to a type in the BOM. Here we have created a field called cust that will be able to hold instances of the Customer class instances:

Then a Script Task can be dragged onto the process diagram from the Tasks palette:

View the Script Task properties and from Script Defined As menu, select JavaScript:

The Describe Task Script dialog is displayed. Type the script.

It is very important to understand that when a process starts, the cust process data field will not contain or refer to an instance of the Customer class, it just has the ability to. So the first thing to do before attempting to access the attributes of the process data field is create an instance of the Customer object and assign it to the cust process data field. The instances of the Customer class are created by the "Customer Factory Method", the name of the factory that creates Customer instances is based on the name of the BOM package that contains the Customer class as described in the previous section.

data.cust = factory.com_example_data.createCustomer();