I was replying to OTN forum post regarding OSB For each action at :
So thought of writing it down to make it more clear.....
- I have made xml based proxy service.
2. I assumed the payload would be
3. Assigned $body to companycollreq ( user defined variable) using Assign action
4. To keep a count of companycollection elemennt in the request payload
Assign count($companycollreq/request/CompanyCollection) to companyCount
5. Now use a for each action to iterate over companycollection
For each expression would like as:
For Each variable companycoll in ./request/CompanyCollection of variable companycollreq
Indexed by variable currIndex with total count in variable companycount
6. Under Do
I am logging the companycollection element based upon the currindex count in for loop.
This is important as we need to pass payload under iteration in for loop.
Assign $companycollreq/request/CompanyCollection[xs:int($currIndex)] in log action with annotation
Now Testing is done with above payload.
In Console logs obtained:
This is how for each action works.
Log action runs twice as companycollection count was two in payload passed.
In place of log action we can use service callout/Publish/Java callout .
The payload passed must contain currIndex as xquery predicates expression while passing value to other services being called from for loop.