Sunday, September 28, 2014

BPEL 1.1: While Activity & Traverse through Collection

Following topic will help you to understand one of BPEL Advanced activities 'While' usage & how to traverse/iterate through data collection.

1. Create two variables in your BPEL as mentioned below.

    <variable name="Counter" type="xsd:int"/>
    <variable name="Nodes" type="xsd:int"/>

2. Add Assign activity to flow.

>  set Counter variable value to 1 &
>  count the number of nodes in data collection and assign to Nodes variable
    <assign name="InitializeVariables">
        <from expression="1"/>
        <to variable="Counter"/>
        <from expression="ora:countNodes('InputVariable','EmpCollection','/ns2:EmpCollection/ns2:Emp')"/>
        <to variable="Nodes"/>

Note: Typically use the expression builder to identify the element then replace the bpws:getVariableData with ora:countNodes.

3. Add While activity and specify condition as needed.

   condition="bpws:getVariableData('Counter') &lt;= bpws:getVariableData('Nodes')"
4. Access record at particular index in the array using []. Specify Counter variable to iterate through each record in collection.


5. Increment Counter in the end. Sample While Activity block provided below.

    <while name="WhileMultiNodes"
           condition="bpws:getVariableData('Counter') &lt;= bpws:getVariableData('Nodes')">
      <sequence name="Sequence">
        <assign name="AssignValue">
            <from variable="InputVariable"
            <to variable="empID"/>
        <assign name="IncrementCounter">
            <from expression="bpws:getVariableData('Counter') + 1"/>
            <to variable="Counter"/>

No comments:

Post a Comment

Provide your thoughts !