In this article we will see how to implement FOR loop in BPEL process. Follow the below steps to print the series of numbers using for-each activity.
- Create a project under same application. Go to File -> New -> Project -> SOA Project. Enter project name ForEachDemo and then select Composite With BPEL Process in the next wizard
- Click on FINISH button and BPEL Process creation wizard will open. Enter BPEL process name and select Synchronous BPEL Process option as template type. Select the checkbox Expose as a SOAP service.
- Create two variables in the BPEL process. Click on Variable icon in the main scope. The variables will be a�� loopcounter and resultvar and variable type will be integer.
- Select ASSIGN activity from component palette and drag and drop it in between receiveInput and replyOutput.
- Double click on Assign activity and map loopcounter value to input variable
- Select FOR-EACH activity from Structured Activities component and drag and drop it after Assign activity.
- Double click on ForEach activity and enter counter name as loopcounter. Go to Counter Values tab and enter 1 as start value and input payload as target value.
- Drag and drop an ASSIGN activity within FOR-EACH activity
- Double click on assign activity and add an expression to the resultvar like below screenshot
- Now drag and drop another ASSIGN activity after FOR-EACH activity
- Map resultvar to output payload in the assign activity
- Save the project and the BPEL process will look like below screenshot
- Deploy the project and test it in EM console.
- Enter 5 as input string and see the result.