How to use the Loop Unit

From Wiki

Jump to: navigation, search


The Loop Unit

The loop unit is an operation unit designed to iterate over an array of objects. At each iteration the unit provides as output parameters both the current object and the current index. The loop unit must be the source of two distinct OK links: one is followed when the iteration is not finished, and must be marked with the 'next' link code; the other is followed when the iteration has reached its end, and must be marked with the 'end' link code. In the following example a loop unit is used to send a newsletter to every selected customer automatically. This is done by iterating over all the selected customers and sending an email (composed with the Script Unit) with the Mail Unit to each one. When the loop unit has iterated over all the customers, it follows the OK Link with the 'end' code.

Image:Loop unit first example II.PNG

The loop unit is configured to iterate over the list of selected customers' emails:

Image:Loop unit input coupling II.PNG

Every time the OK Link with the 'next' code is followed, the link provides as parameter a new element of the list (the next selected customer email):

Image:Loop unit next element coupling II.PNG

Secondary Array

It is possible to add other arrays to the iteration, using the "Add secondary array" command on the Loop Unit. For each secondary array the loop unit requires an input parameter, i.e. the array of objects to iterate over, and provides an output parameter, i.e. the current element of the array. Note that the iteration is controlled by the mandatory input array, and therefore the length of iteration is not influenced by secondary arrays: if the current iteration index is greater than the size of the secondary array, a null value is provided in output.

As an example, suppose that we want to customize the body of the email adding the username of the customer. A secondary array containing the name of the current customer is needed in order to use it at every iteration.

Image:Loop unit add secondary array II.PNG

Now it is possible to associate the new secondary array with the list of usernames, in order to compose a customized email.

Image:Loop unit secondary array input coupling II.PNG

With a transport link the username is transported to the Script Unit.

Image:Loop unit secondary array output coupling.PNG


Related articles:
Category Difficulty Refers
Context Parameters Web Model Beginner Get Unit
Set Unit
Reset Unit
Create a "Hello world" application Web Model Beginner Site View
WebML
WebRatio
Create a "Simple data centric" web application Web Model Beginner Site View
WebML
WebRatio
Custom Locations and Master pages Web Model Beginner Master Page
Custom Location
Getting started with Groovy Technical Reference Beginner Script Unit
Template
… further results












Personal tools