Martini Services While Step
Overview
The while step is a control flow element similar to the while statement found in Java and other programming languages, augmented with additional features. It repeatedly executes a block of steps as long as a specified condition is met.
Execution Logic
The execution of the while step depends on two properties: the Expression and the While On Error. The behavior varies based on the result of the Expression evaluation:
-
Numeric Expressions: If the Expression results in a Number (primitive or object) or a String with a numeric value, the step checks if this number is less than or equal to the current execution count. If true, the step repeats.
-
Boolean Expressions: If the Expression is a boolean or a Boolean object, its value directly determines whether to repeat the step.
-
String Expressions: Non-numeric Strings are evaluated for a "true" (case insensitive) value to decide on repetition.
-
Other Types: Any other result type from the Expression leads to an exception.
Introduced Variables
During execution, two variables are introduced:
$index
: A zero-based counter, incrementing after each iteration.$count
: A one-based counter, also incrementing post iteration.
Display in Editor
- Numeric Expression: Displayed as
While $index < <expressionValue>
. - Other Expressions: Shown as
While <expressionValue>
.
Error Handling
The While On Error property, when set to true, allows the step to rerun only if both the Expression condition is met and an exception occurs in child steps. This feature is particularly useful for retry operations, like connecting to remote servers. If set to false, exceptions are not caught internally and are propagated upwards.
Array Manipulation
An Output Array property is available for mapping or transforming data within the while step, similar to an iterate step. This property simplifies adding elements to a designated array or cursor.
In the context of the while step, the Mapper view will show changes: the $index
and $count
variables become available, and the target array (e.g., myArray
) shifts from an array representation to a singular item.
Additional Features
- Delay: Configurable delay at the end of each iteration.
- Cursor Management: Option to close output cursors upon completion via the Close Output Cursor setting.