Welcome to K2 Underground Sign In | Join | Help

Looping through an Activity for each SmartObject List item

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

K2 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

 

Published Tuesday, August 26, 2008 10:48 AM by russforster
Filed under: , ,

Comments

# re: Looping through an Activity for each SmartObject List item

Tuesday, August 26, 2008 3:26 AM by russforster

# re: Looping through an Activity for each SmartObject List item

Wednesday, August 27, 2008 3:27 PM by DavidL

While generally used with the IPC event, you can also use the same techniques with other events.

Anonymous comments are disabled