Example: Array notations in automation scripts

When variables with relationship path bindings are resolved at run time, the scripting framework constructs and inserts a standard array object into the script code. The script code references the required array of values by the variable name you declared in the launch point configuration.

Example

Business logic needs to be implemented so that the total material cost that is associated with a work order is calculated. An object launch point is defined on the WORKORDER business object. You define a variable called matcostarray to represent the array of material costs. The binding for this variable uses a relationship path MATUSETRANS.linecost*. The relationship path traverses a pre defined relationship called MATUSETRANS. Traversing this relationship gives the script access to all of the MATUSETRANS business object records associated with the work order to retrieve all material costs. The variable is directly referenced in the script code:

if matcostarray is not None:
        if len(matcostarray)>0:
                for value in matcostarray:
                        if value is not None and value !=0:
                               totalmatcost += value
In the fragment of script code written with Jython, the following logic is implemented:
  • Check whether the array object is valid.
  • Check whether the array contains multiple elements.
  • Loop through the array to retrieve each element.
  • Sum the individual values into the local variable totalmatcost.