Loop Node
Description
Loops allow you to iterate through the same pattern or steps more than one time, based on identified rules. You can model loop functionality manually or you can use the Iterator part to set up efficient loops. With the Iterator part, you reduce the modelling complexity and risk of errors, but you also improve the runtime performance of the application because the number of steps the system walks through is reduced.
Use
With the Iterator Part
With the iterator part, assign a variable the element to be used from a collection. The system processes the element, increases the counter, and loops back to the rule. Here is an example of a loop created with the loop part:
Using the Iterator Part
To add a loop part, do the following:
- Click the routing option in the toolbox menu and select iterator. The system adds a process node that includes a Loop entry.
- Double-click the Loop line item.
- Enter the name of the collection through which to iterate in the Collection field.
- Using the Loop method dropdown menu, select the iteration method. An explanation of each option is in the Collection Types section below.
- Enter the name of data object into which the the current collection object is stored in the Current item path field.
Tips & Tricks
For simpler processing steps, use the current item path in calculations, setting temporary variables etc. For example, $(current.variableA) can be used in a rule if $(current.variableA) >X then....
For more complex processing of data outside of the loop collection, enter your own name for the loop counter so you can reference the cycle count.
Collection Types
The iterator part can either loop through the indexed elements of a collection, through the keys of the collection elements, or both. You set which of these to use in the Loop method dropdown menu in the iterator part.
Indexed Elements
These are used in a simple collection, for example { "example", "test", "data", { "object" } }. This collection contains four entries and the order of the elements is guaranteed to remain the same. The following indexed collection is used in the example project at the bottom of this topic:
Named Elements
These are used in dictionary-like tables; for example, { field1 = "first field", field2 = "second field", additional = { "some object"} }. This dictionary has three elements, but because of the keys/names, the order cannot be guaranteed. This means the Designer user cannot rely on the elements being processed in the SAME order each time the loop runs.
The following named collection is used in the example project at the bottom of this topic:
Complex Objects
These can combine both named and indexed elements; for example, { "example", "test", "data", { "object" }; n=4, field1 = "first field", field2 = "second field", additional = { "some object"} }. This item has four entries based on index and three dictionary elements based on name. The 'n' key is ignored. Again, the order of indexed elements is guaranteed and the order of the named elements is not guaranteed.
The following mixed collection is used in the example project at the bottom of this topic:
To assist predictability of the name/key order, it is possible to define the sorting order of the names, either unsorted, ascending or descending.
Editor Fields
Tab |
Field |
Type / Options |
Optional/ |
Description |
Basic |
Collection |
data object |
M |
Name of the collection that contains the elements to be passed into the loop in data object [Current item path] |
Basic |
Loop method |
dropdown menu |
M |
This defines the way the collection is iterated and includes the following possible loop methods:
|
Basic |
Current item path |
data object | M | This is the name of the data object into which the current collection object is stored. |
Advanced |
Current index path |
data object | O | This is the name of the data object where the current index is stored. This is the index of the indexed elements. This parameter is hidden when 'Named' is selected as loop method. NOTE: This index can be different than the loop counter/number of iterations the loop has made; for example, when gaps are present in the index, this index will still indicate the actual index of the current item, while the total counter will contain the number of iterations the loop has taken. |
Advanced |
Current name index path |
data object | O | This is the name of the data object where the current name/key is stored. It is hidden when 'Indexed' is selected as loop method. |
Advanced |
Loop counter path |
data object | O | This is the name of the data object where the loop counter is stored. This is the counter that counts the iterations the loop has taken, starting with the indexed elements and finishing with the named elements. |
Advanced |
Named indices collection path |
data object | O | This is the name of the data object where the list of all keys/names of the collection is stored. It is hidden when 'Indexed' is selected as loop method. |
Advanced |
Current name path |
data object | O | This is the name of the dataobject where the name/key of the current item is stored. It is hidden when 'Indexed' is selected as loop method. |
Advanced |
Named elements sort method |
dropdown menu | O | This option defines the sort order for the named elements:
|
NOTE: All advanced data objects are automatically filled when running through the loop and cleared again when exiting the loop.
Example
Please download and import one of the following example projects in your workspace.