Let us now implement the same scenario using the <forEach>
loop:
<while>
loop example; therefore, we will add another BPEL process component to the composite diagram. We will call it BookOrderForEachBPEL
:BookWarehousingBPEL
:<forEach>
activity to the process flow by dragging-and-dropping For Each from the Components palette (you will find it under Structured Activities):ForEach1
activity and set Name as ManageOrders
and name of the counter variable (Counter name) as OrderCounter
:1
and the end value is the count($inputVariable.payload/ns1:BookData)
expression. With this expression, we will count the number of books in the array. This is exactly the number of times we wish the <forEach>
loop to repeat:<forEach>
loop, we will extract the book order item from the array, and prepare the request for the BookWarehousingBPEL
process and invoke it. We do not need to manually increase the counter however.<invoke>
activity. We will name the activity InvokeBookWarehousing
. We will also create two global variables on the fly, BookWarehousingRequest
and BookWarehousingResponse
:<assign>
activity to prepare the request. We will add the <assign>
activity before the <invoke>
activity and set the following copy expression:As you can see, we will copy the $inputVariable.payload/ns1:BookData[$OrderCounter]
order item to the $BookWarehousingRequest.payload/ns1:BookData
element.