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") then a List is used to manage the field, and values must be added to the field using List methods. Otherwise, if the multiplicity is 1 (for example, multiplicity is "1" or "0..1"), then a straightforward assignment can be used.
When the multiplicity of an attribute is greater than one, a List 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 = com_example_scriptingguide_Factory.createOrderLine(); orderline.partNumber = 10023; orderline.quantity = 3; order.orderlines.add(orderline); orderline = com_example_scriptingguide_Factory.createOrderLine(); orderline.partNumber = 10056; orderline.quantity = 1; order.orderlines.add(orderline); |
or using the ScriptUtil.copy() method:
var orderline = com_example_scriptingguide_Factory.createOrderLine(); orderline.partNumber = 10023; orderline.quantity = 3; order.orderlines.add(orderline); orderline = ScriptUtil.copy(orderline); orderline.partNumber = 10056; orderline.quantity = 1; order.orderlines.add(orderline); |
The List object provides methods for finding out how many items there are in the list, accessing particular entries in the list, and enumerating the list. Some further examples of working with multi-instance fields and attributes are provided in the following sections:
- Looping Through Lists and Copying Elements in Lists.
- Scripting Containment Relationships.
- Using the List set() Method.
- Removing an Item from a List or a Containment Relationship.
To learn more about what you can do with the List object, see Using the List set() Method.