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

 


Posted Tue, Aug 26 2008 10:48 AM by russforster
Filed under: , ,

Comments

russforster wrote re: Looping through an Activity for each SmartObject List item
on Tue, Aug 26 2008 3:26 AM
DavidL wrote re: Looping through an Activity for each SmartObject List item
on Wed, Aug 27 2008 3:27 PM

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

xymox wrote re: Looping through an Activity for each SmartObject List item
on Thu, Mar 12 2009 12:03 PM

what about running other activities, how do you design time access the instance data?

what say ye?

jan wrote re: Looping through an Activity for each SmartObject List item
on Tue, Jun 2 2009 9:25 AM

This is definitly cooooool :-)

amankazi wrote re: Looping through an Activity for each SmartObject List item
on Thu, Jul 2 2009 11:11 PM

How can I stop my main process not to move to next activity unless all the instances of the sub-process are completed?

kbamar83 wrote re: Looping through an Activity for each SmartObject List item
on Wed, Jan 13 2010 12:13 PM

how to pass each item to the child IPC?

daviddrewette wrote re: Looping through an Activity for each SmartObject List item
on Tue, Dec 18 2012 6:58 AM

Hi,

your images seem to have disappeared?

Can you possibly get them back please? This is a great tutorial for what I am doing right now,

thanks

daviddrewette wrote re: Looping through an Activity for each SmartObject List item
on Wed, Dec 19 2012 12:35 AM

forget that last message from me.

Photobucket is blocked on our internal systems!

Smaira wrote re: Looping through an Activity for each SmartObject List item
on Mon, Mar 18 2013 4:59 AM

Hi,

i have a single process which returns a list of users.  effectively a list of orders according to this example.  How do i process each of the items to send an email showing the list of returned values?

at the moment it is only processing the 1st item on the list.