Enter your keyword

post

For each action in Oracle Service BUS 12c

In Oracle Service Bus 12c you can use the for-each action to iterate multiple elements in your payload.

I want this post to show you how we can use for each component of the OSB 12c to iterate through a list of users.

Suppose we have the payload

<USERS>
<USER>
<ID>1</ID>
<NAME>Ankur</NAME>
</USER>
<USER>
<ID>2</ID>
<NAME>Ankit</NAME>
</USER>
</USERS>

and want to log the USER node.

Let’s go through an example and see how For Each component works:

1) Create a Service Bus application with Service Bus project

2) Create a pipeline

3) Double click on the pipeline and drag and drop the pipeline pair node. Drag and drop the For Each component from the component pallet under the Request stage:

4) Configure the For Each properties like below:

Let’s see the properties:

  • For Each Value: Configure the variable that need to iterate. In our case we have configured body as we have the payload in our body only.
  • Expression: Which node you need to iterate. In our case we have configured ./USERS/USER as we need to iterate each USER node from the payload.
  • Value Variable: You can leave it blank, not required.
  • Index Variable: This is the variable that keeps the track of current index.
  • Counter Variable: This is the variable that contains the total no of nodes available in the payload.
5) Drag the log activity from the component pallet under the For Each and put the expression:
$body/USERS/USER[xs:int($currIndex)]

Let’s run the pipeline and see the logs
That’s it !!

Some Toughts (4)

  1. Anonymous
    added on 31 May, 2017
    Reply

    Thanks Ankur, Can you please give an example using split join like this? Regards, Sanddy

  2. added on 28 Jun, 2019
    Reply

    ANkur, can you tell me one thing…:
    I need to know how to delete section "Offers" if within parameter "delete" is equal 1.
    I have tried to use for-each action and then delete action but either I am getting validation error or the whole sections $BodyMsgRespose/Offers are deleted

    br, Arek

    I am not able to use code below in Xpath to choose correct section Offers to be deleted.
    "v1:BodyMsgRespose/v1:Offers[($currIndex)]"

    Request:

    2S43/0042

    PODKŁADY TOROWE BETONOWE Z PRZYTWIERDZENIAMI

    2S43
    Przebudowa linii tramwajowej w Krakowie
    A37HB
    PODKŁADY TOROWE BETONOWE
    A0Z4
    2014-01-09T13:53:28.617
    1
    0

    B5ZJ
    KK
    2217590.0000
    0
    0

    AH4B
    KK
    2238734.0000
    0
    1

    AQFD
    KK
    2432112.0000
    0
    0

  3. added on 3 Jul, 2019
    Reply

    This comment has been removed by the author.

  4. added on 18 Jul, 2019
    Reply

    Thankyou for sharingerp software

Leave a Reply

Your email address will not be published.