Multiple Instances of a BOM Class in a BOM Class Attribute
Just as we defined Process Fields that contained Multiple Instances of Customer Business Objects in the previous section, we can also specify that an attribute of a BOM Class can have and must have multiple instances, for example, an Order may contain multiple OrderLine objects.
In BOM Editor, this is configured by setting the multiplicity of the attribute, as shown here:
The above screenshot shows some example values that can be used to specify the multiplicity, however, other values can also be used, for example, 3..6 would mean between 3 and 6 instances must be added to the field.
If the multiplicity is greater than one (e.g. "*"; "1..*" or "3..6"), an Array is used to manage the field, and values must be added to the field using Arrays. Otherwise, if the multiplicity is 1 (for example, multiplicity is "1" or "0..1"), a straightforward assignment can be used.
When the multiplicity of an attribute is greater than one, an Array is used to manage the data at runtime, in the same way Process Fields are managed when the Array checkbox is set in the Field Properties. To manage the multiple orderlines associated with an Order, the following script can be written.
var orderline = data.com_example_data_createOrderLine(); orderline.partNumber = 10023; orderline.quantity = 3; data.order.orderlines.push(orderline); orderline = factory.com_example_data_createOrderLine(); orderline.partNumber = 10056; orderline.quantity = 1; data.order.orderlines.push(orderline); |
or using the bpm.scriptUtil.copy() method:
var orderline = factory.com_example_data_Factory.createOrderLine();
orderline.partNumber = 10023;
orderline.quantity = 3;
data.order.orderlines.push(orderline);
orderline = bpm.scriptUtil.copy(orderline);
orderline.partNumber = 10056;
orderline.quantity = 1;
data.order.orderlines.push(orderline);
|
Arrays provide methods for finding out how many items there are in the array, accessing particular entries in the array, and enumerating the array.