Today I discovered a feature within K2 [blackpearl], the ability to loop through a list of items and execute a set of Events for each item – without having to write a line of code!
A simple Order Processing example would illustrate my business case. For demonstration purposes I will assume an Order has multiple Order Items. A K2 Process (Process Order) instance has been started for an individual order. Whilst running this process we need to spawn a sub-process (Process Order Item) for each Order Item.
I have created a SmartObject (SmartBox) called “OrderItems” which has a List Method returning all Items for a given Order.

"Process Order" & "Process Order Item" processes
Process Order Process has one Process Data Field
· OrderId (Number)
The Process Order Item process has two
· OrderId (Number)
· OrderItemId (String) – Note this has to be a String as K2 will pass this value into the Process
We are going to start an instance of “Process Order Item” for each Item returned by our SmartObject. Within the “Process Order Items” set the “Destination Rule Option” to be “Plan per Slot (no destinations)”.
Select the “Id” field from the “OrderItems” SmartObject’s List method.
Important: The field you select here will be used to identifying each loop instance.

Pass the OrderId (Process Data Field) as an Input for the SmartObject.

Click Finish.
Now when we configure the IPC Event we are able to get the OrderItem’s Id Field by access the “Activity Destination Instance/Instance Data” (String).

We then Map the required fields


A final step would be to configure the “Process Order Items” Activity Succeeding Rule to ensure all instances have completed.

Russell Forster
Posted
Tue, Aug 26 2008 10:48 AM
by
russforster