Monday, January 18, 2016

For each activity in BPEL 2.0


With BPEL 2.0 a lot of new changes has come.

Earlier if you had to implement a loop you will use flowN or while loop, however with BPEL 2.0 we now have a for each activity and it is very easy to use.

Let suppose you have a xml schema

<xsd:element name="CompleteOrder">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="OrderNumber" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Order" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy="""/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>


You want to call an adapter for every order.

you can do this very easily using a for each activity.

Drag and drop a for each activity in the process.

Specify the counter name and copy it as this is the counter variable name that needs to be used inside a process to loop for element



Now go to counter Value tab and specify the initial counter as 1

Again for Final value get the count of OrderNumber as shown in the diagram.

As you can see from the schmea OrderNumber is the repeating element so count() is used to get the final number.



NOw we are almost done ,

Only thing required is to use the counter variable during your assign activity .


you have to use it in the same as you used to do in case of a loop.

For the repeating node you have to use following syntax

RepeatingNode[$ForeachCounter]


As you can see ForeachCounter is the same variable we have defined in the very first step.

So a normal assign will have and entry like this.




your assign should be within the scope of for each



No comments: