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.

<IF target="Grid" test="VisibleRowsCount" mode="LessThan" value="5"> 
	<echo value="VISIBLE IN GRID < 2"/>
</IF>
XML

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
Target"Tree"
"Grid" (for default grid) or Grid name
"Var" for variables declared with SetVar
"List"
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

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.


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

Example Script 

<ytriaAutomation>
	<While max="3">
		<Echo value="1. ======> while index: {%loopindex%}"/>
	</While>
	<While>
		<Echo value="2. ======> while index: {%loopindex%}"/>
			<if target="var" test="{%loopindex%}" mode="equals" value="3">
				<breakLoop/>
			</if>
	</While>
	<While target="var" test="{%loopindex%}" mode="LessOrEquals" value="3">
		<Echo value="3. ======> while index: {%loopindex%}"/>
	</While>
</ytriaAutomation>
XML