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">
      <copy>
        <from expression="1"/>
        <to variable="Counter"/>
      </copy>
      <copy>
        <from expression="ora:countNodes('InputVariable','EmpCollection','/ns2:EmpCollection/ns2:Emp')"/>
        <to variable="Nodes"/>
      </copy>
    </assign>

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.

    /ns2:EmpCollection/ns2:Emp[bpws:getVariableData('Counter')]/ns2:empId

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">
          <copy>
            <from variable="InputVariable"
                  part="EmpCollection"
                  query="/ns2:EmpCollection/ns2:Emp[bpws:getVariableData('Counter')]/ns2:empId"/>
            <to variable="empID"/>
          </copy>
        </assign>
        <assign name="IncrementCounter">
          <copy>
            <from expression="bpws:getVariableData('Counter') + 1"/>
            <to variable="Counter"/>
          </copy>
        </assign>
      </sequence>
    </while>

No comments:

Post a Comment

Provide your thoughts !