Skip to main content
Skip table of contents

If

Tag: If

The If function sets a branching condition in an XML automation script. The actions within the IF block are executed only if the condition is evaluated as true. The automation trace signals when an action is not executed due to its enclosing IF being evaluated as false

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


Detailed Description

Each of the three different IF action scenarios may be combined together within the same script block if needed, as each IF statement will be evaluated individually.

IF actions can also be nested:



NOTEALL IF actions will be tested unless they are nested and the higher IF condition does not take effect.


Tag Attributes


There are three main scenarios when employing IF actions; each one has a specific set of attributes possible:

1-Tag Attributes when Applicable to Loops

AttributesAttribute ValuesValue DescriptionComment
IndexFirst

Last

Other

Unique

*or a user definable integer value

The position of the iteration within the Loop to which the the IF action will be connected - Required

The Index attribute is exclusive; it cannot be combined with other tag attributes.

2-Tag Attributes when Applicable to Tree or Grid Tests

AttributesAttribute ValuesValue Description
TargetApplicable Grid CodeTargets selection tree

Targets desired grid - Required

TestFocusRoot

SelectionCount

VisibleRowsCount

Sets what the IF action is "about"
A tree node or the number of selections in a selection tree, the number of selections, or the number of visible rows within a grid - Required

ModeEquals
NotEquals
GreaterThan
GreaterOrEquals
LessThan
LessOrEquals
Begins
NotBegins
Ends
NotEnds
Contains
NotContains
Exists

Declares comparison type - Required

ValueTrue / False

User definable integer

The value to use as a determinant - Required

3-Tag Attributes when Applicable to Variables

AttributesAttribute ValuesValue Description
TargetVarTriggers testing of the variables (must be set in SetVar actions) - Required
TestVariable nameThe variable to test - Required
Mode

Equals

NotEquals

GreaterThan

GreaterOrEquals

LessThan

LessOrEquals

Begins

NotBegins

Ends

NotEnds

Contains

NotContains

Exists

IsIn

IsNotIn

Declares comparison type - Required
ValueUser defined stringThe value to use as a determinant - Required

4. Tag Attributes when applicable to a List

AttributesValue Attribute
TargetList
TestName of list to test for - Required
ValueTrue or FalseRequired
Mode

Exists: does the list exist at all

Empty: does the list contain at least one element

Required

<if Mode='Empty' Test='List123' Value='True' Target='list'>
     <echo value='List123 is empty'/>
</if>

5. Tag Attributes when applicable to a User question

With target "Question", all above parameters are ignored and the following are used:

A Message Box is displayed with two buttons (OK and Cancel). When the user clicks the OK button, IF is set as true and its sub-actions are executed. When the user clicks the Cancel button, IF is set as false and its sub-actions are ignored, its ELSE clause is executed if present.

Without AutoClose, script execution is interrupted until one choice is manually made in the dialog box.

With AutoClose, the dialog box is closed after the number of seconds set as value and script execution resumes as if the OK choice had been made.

AttributesValue Attribute
Target"Question"
AutoClose

Number of seconds before the dialog is closed with OK  - Optional

If set, must be a positive number.

TitleN/A - Optional
MessageN/A - Required (But can be empty)
MessageExtendN/A - Optional
ButtonTextOkN/A - Optional (Defaults to OK")
ButtonTextCancelN/A - Optional (Defaults to "Cancel)
ImageSVG ID of the left-side image - Optional

Detailed Description

XML
<ShowGroups>
	<if Target="Question" image="question" Title="Filter groups?" Message="Apply filter" MessageExtended="from a list">
		<List name="O365GroupList" Action="SetVar" GType="Distribution list"/>
			<FilterFromList ListName="O365GroupList">
				<SetParam columnID="groupType" value="GType"/>
			/FilterFromList>
	</if>
	<else>
		<MsgBox image="thumb" Title="The groups" Message="Not filtered" MessageExtended="at all"/>
	</else>
</ShowGroups>


Nesting:

  • An IF can be nested within
  • Another IF
  • A LOOP
  • A modal action (action that happens within a modal dialog like Values, NotesIni etc)

Example Script - with the scanEZ tree

XML
<Focus Target="Tree" Category="Profile Documents" Type="ColorProfile"/><!-- if focus tree element is not found, focus is set at tree root -- >
<If target="Tree" test="focusRoot" mode="equals" value="false"> <!-- if the tree focus is not at root level, ColorProfile was found -->
	<MySelection lastFocus="true">
		<Setparam Field="MySelectionName" Value="TheProfile1"/>
		<Setparam Field="TitleOptionType" Value="Formula"/>
		<Setparam Field="TitleOptionFormula" Value="@Implode(@DbName;"!!")"/>
	</MySelection>
</If>

Example Script - with a grid

XML
<!-- do some filtering on the grid -->
	<If target="Grid" test="VisibleRowsCount" mode="LessThan" value="5"> <!-- if the main grid has less than 5 visible rows -->
<!-- do things -->
	</If>

Testing the availability of a grid:

XML
		<if target="grid">
			<echo value='GRID EXISTS'/>
		</if>

is equivalent to:

		<if target="grid" mode="Exists" value="true">
			<echo value='GRID EXISTS'/>
		</if>

In this sample, we are checking if a grid is currently available to be automated.

When the script context is not clear, this test avoids getting an error when running grid automation while no grid is available.

The parameter value "grid" in: target="grid" can be replaced by any grid automation name.


Loop tests

XML
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atapp.nsf"/>
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atest5.nsf"/>
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atest4.nsf"/>
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atest3.nsf"/>
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atest2.nsf"/>
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atest1.nsf"/>
	<loop list="MyList">
		<If index="last">
			<echo value="LOOP LAST"/>
		</If>
		<If index="first">
			<echo value="LOOP FIRST"/>
		</If>
		<If index="2">
			<echo value="LOOP 2"/>
		</If>
		<If index="666">
			<echo value="VADE RETRO"/>
		</If>
		<If index="4">
			<echo value="LOOP 4"/>
		</If>
	</loop>

Grid & tree content tests

XML
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<ytriaAutomation Application="databaseEZ" ApplicationVersion="11.1.2.88" Version="1.0">
	<echo mode="false"/>
	<Load Server="ytest-MD/TESTING" partial="true">
		<Load Database="AutoTest\lm_us_8.nsf" Select="True"/>
		<Load Database="AutoTest\lm_nab_8.nsf" Select="True"/>
		<Load Database="AutoTest\custinfo_s03.nsf" Select="True"/>
		<Load Database="websecuritystore.ntf" Select="True"/>
		<Load Database="YtriaLogFile-2013-03.nsf" Select="True"/>
	</Load>
	<IF target="tree" test="SelectionCount" mode="GreaterThan" value="3">
		<echo value="SELECTED IN TREE > 3"/>
	</IF>
	<IF target="tree" test="SelectionCount" mode="LessThan" value="10">
		<echo value="SELECTED IN TREE < 10"/>
	</IF>
	<IF target="tree" test="SelectionCount" mode="equals" value="5">
		<echo value="SELECTED IN TREE = 5"/>
	</IF>
	<IF target="tree" test="SelectionCount" mode="equals" value="100">
		<echo value="SELECTED IN TREE = 100"/>
	</IF>
	<IF target="grid" test="VisibleRowsCount" mode="GreaterThan" value="3">
		<echo value="VISIBLE IN GRID > 3"/>
	</IF>
	<IF target="grid" test="VisibleRowsCount" mode="LessThan" value="10">
		<echo value="VISIBLE IN GRID < 10"/>
	</IF>
	<IF target="grid" test="VisibleRowsCount" mode="equals" value="5">
		<echo value="VISIBLE IN GRID = 5"/>
	</IF>
	<IF target="grid" test="VisibleRowsCount" mode="equals" value="100">
		<echo value="VISIBLE IN GRID = 100"/>
	</IF>
</ytriaAutomation>


List Existential Test

By default, the LIST test checks if the list exists:
- Mode defaults to "Exists" (no other mode value shall be accepted when Target is set to "List")
- Value defaults to "True"

XML
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atapp.nsf"/>
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atest5.nsf"/>
	<IF target="list" test ="MyList">
		<echo value="MyList exists! Yay"/>
	</IF>
	<IF target="list" test ="MyList" value="False">
		<echo value="MyList DOES NOT exist. Booo"/>
	</IF>
	<ELSE>
		<echo value="MyList still exists! YO"/>
	</ELSE>
	<IF target="list" test ="GhostList" value="False">
		<echo value="GhostList DOES NOT exist.."/>
	</IF>
	<ELSE>
		<echo value="GhostList exists!"/>
	</ELSE>


XML
<ytriaAutomation console="false">

	<SetVar MyThings="42"/>
	<IF target="var" test="{%MyThings%}" mode="IsIn" value="312:Georges:42:666">
		<MsgBox Message="42"/>
	</IF>

	<IF target="var" test="{%MyThings%}" mode="IsNotIn" value="Mugre">
		<MsgBox Message="Not Mugre"/>
	</IF>

</ytriaAutomation>
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.