0

I am using WSO2 BPS and WSO2 DSS.
DSS has 2 services as below:
(1) Returns list of status and
(2) Inserts a record into table.

I succeeded invoking both the DSS services from BPEL Workflow. But I need to achieve the following thing.
My 1st DSS will return "List of Status". I have to iterate(using 'forEach' or 'while' or ...) that response and pick particular node(StatusDescription) from it and use it for the next DSS call. My 1st DSS response is below.

<Response xmlns="http://ws.wso2.org/dataservice">
    <Status>
        <StatusId>1</StatusId>
        <StatusDescription>Active</StatusDescription>
    </Status>
    <Status>
        <StatusId>2</StatusId>
        <StatusDescription>Inactive</StatusDescription>
    </Status>
</Response>  

Can anyone suggest some tutorial or code snippet that would iterate through above DSS response? i.e, My bpel:finalCounterValue will be '2' as there are 2 'Status' nodes in the above XML.

Thanks in Advance.

Vijay Krish
  • 297
  • 6
  • 23
  • There is no reason to iterate using BPEL activities. Just use an ordinary XPath expression in an assignment. Something like `$VariableName/*[child::StatusId = 2]/StatusDescription` (omitting namespaces) should do the trick. – joergl Apr 19 '13 at 14:45
  • You are right joergl. But the above response is only a sample. In real, the number of status may differ(dynamic). So, I have to look into some other option. Thanks. – Vijay Krish Apr 22 '13 at 06:25

1 Answers1

1

I found the the way to iterate the nodes. Please find the code snippet below.

<bpel:forEach parallel="no" counterName="Counter" name="ForEach">
            <bpel:startCounterValue>
                <![CDATA[1]]>
            </bpel:startCounterValue>
            <bpel:finalCounterValue>                
                <![CDATA[count($GetStatusPLResponse.parameters/ns:Status)]]>
            </bpel:finalCounterValue>
            <bpel:scope>
                <!-- Some activity goes here. Say Assign or Invoke or .... -->
            </bpel:scope>
        </bpel:forEach>  

The count method available under the namespace xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable" helps us to find count of nodes('Status').
The count method returns the value '2' and so 'forEach' iterates twice.

Have Happy Learning.

Vijay Krish
  • 297
  • 6
  • 23