Tag: While

The While function creates a a loop without having to use the mechanics of the LOOP action. In short, no lists are needed.

Detailed Description

The While loop is infinite by default. It must be made to stop with a BREAKLOOP action inside the While block, or with a condition directly set at the While level.
While is like a LOOP and an IF combined.

Setting conditions at the While level is similar to the conditions for IF.
While has one more conditional attribute "Max=n" which stops the While after n iterations .

Variables from LOOP like {%LoopIndex%} are available with While.

It is easy to create an infinite loop with While. If it happens, the application freezes (Notes apps) or makes it impossible to run any other automation (job or script, sapio365). The only way to break an infinite While loop is to hit the Cancel Automation button on the console.

Tag Attributes

AttributesValue Description
MaxNumber setting the maximum number of iterations
IndexPosition of current iteration within a loop. Allowed test values:
  • "First": true if current loop is processing the first element of the list
  • "Last": true if current loop is processing the last element of the list
  • "Other": true if current element is neither first nor last
  • "Unique": true if list has one element only. In this case, Last, First and Other are false.
  • 1, 2, ... n (any integer number)
  • Allows you to check position within a loop and react accordingly. Index is exclusive and cannot be mixed with the parameters below
"Grid" (for default grid) or Grid name
"Var" for variables declared with SetVar
TestWhat the While is about:
  • "FocusRoot": tree top node
  • "SelectionCount": number of selected entries in the tree or grid set in Target (in grid it counts group rows)
  • "VisibleRowsCount": visible rows in grid set in Target
  • Variable name, e.g. {%MyVar%} or list name
ModeHow to compare:
  • "Equals"
  • "NotEquals"
  • "GreaterThan"
  • "GreaterOrEquals"
  • "LessThan"
  • "LessOrEquals"
  • "Begins"
  • "NotBegins"
  • "Ends"
  • "NotEnds"
  • "Contains"
  • "NotContains"
  • "Exists"
ValueTrue / False - Both values only used for FocusRoot and mode for "Exists" lists), or any integer number (SelectionCount, VisibleRowsCount) as well as any text when testing variables
OnErrorAction to take in case of error within While block:
"ExitLoop": break loop and continue with script
"Next": continue to next loop action item

This example shows three ways of running a 3-iterations loop:

Example Scripts

<IF target="Grid" test="VisibleRowsCount" mode="LessThan" value="5"> 
	<echo value="VISIBLE IN GRID < 2"/>
	<While max="3">
		<Echo value="1. ======> while index: {%loopindex%}"/>
		<Echo value="2. ======> while index: {%loopindex%}"/>
			<if target="var" test="{%loopindex%}" mode="equals" value="3">
	<While target="var" test="{%loopindex%}" mode="LessOrEquals" value="3">
		<Echo value="3. ======> while index: {%loopindex%}"/>