WSO2 BPS - Sample Guide - ForEach

Sample Guide - ForEach

Table of Content


Objective

Explains the functionality of <forEach/> construct, where, user can implement repetitive tasks. The tasks can be sequential or parallel based on parallel property. So <forEach/> becomes advantageous comparing to <while/> or <repeatUntil/>, when the repetitive tasks are parallelized.


Prerequisites


Overall Idea

<forEachparallel="no"counterName="ForEachCounter"><startCounterValue>"1"</startCounterValue><finalCounterValue>"3"</finalCounterValue><scopebpmn:label="ForEach"><sequence><assign><copy><from>concat($thisStartRequestMsg.body/text(), $ForEachCounter)</from><to>$thisStartRequestMsg.body</to></copy></assign></sequence></scope></forEach>

In this sample, 3 iterations take place based on the values of <startCounterValue/> and <finalCounterValue/>.

The property counterName can be used as a local variable inside the child scope to store current iteration value. In the above example, ForEachCounter variable value can be 1,2 or 3.

Then inside <scope/>, repetitive task can be implemented.


Note : <forEach/> can have only one <scope/> child.