Skip to main content
Skip table of contents

SetVar: Define a variable

The SetVar automates the action of setting a value to a variable or, in the case of a few "reserved" values, call specific value types on demand. Multiple variables can be set within the same script line.

Detailed Description

The variable can be referenced to in the script after its declaration with SetVar. To reference a variable, enclose it in: {% and: %}.
Variable names are not case sensitive. Referencing a variable that was not previously declared with SetVar does nothing (the string is not replaced).

v16_5_autom_Logic_SetVariables_codeBlock_1.gif

Tag Attributes

AttributesValue Description
Variable Name

Any unreserved name valid in XML. Reserved names are listed on: Variables

Variable ValueAny string or number

Example Scripts

XML
<SetVar Expres1="Help" Expres2="Page"/>
<echo value="{%Expres1%}, {%Expres2%} {%date%}"/>


XML
<!-- declare variables help & page-->
<SetVar help="documentation" page="oui"/>
<!-- use variables help & page-->
<echo value="{%help%}, {%page%} {%page%}? {%date%}"/>

Variables can use other variables

XML
<SetVar help="documentation"/>
<SetVar page="{%help%}"/>
<echo value="{%page%} (help) {%help%}"/>

Loop context

XML
<ytriaAutomation>
	<onerror continue="true" />
	<echo mode="false"/>
	<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atest5.nsf"/>
	<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atest1.nsf"/>
	<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\first idea.nsf"/><!-- does not exist -->
	<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"/>
	<SetVar first idea="YTRIA" ningen="isu" justin="miasma"/>
	<SetVar second idea="Montreal" Office="oui"/>
	<SetVar third idea="{%date%}"/>
	<SetVar now="{%time%}"/>
	<SetVar my last idea="{%first idea%}"/>
	<loop list="MyList">
		<echo value="{%ningen%} {%first idea%}, {%singe%}? {%third idea%}"/>
		<echo value="{%first idea%} and {%first idea%} again, now is {%now%} and {%time%}"/>
		<echo value="{%justin%} is not {%second idea%} {%doesnotexist%} at {%LiStNamE%}: {%loopindex%}/{%listSIZE%}"/>
		<echo value="{%my last idea%} (first idea) {%first idea%}"/>
	</loop>
</ytriaAutomation>

Variable test with IF

Set:
- Target: "Var"
- Test: "{%MyVar%}"
- Mode: any valid operation
- Value: anything, including another variable or combination of variables with other text

XML
<IF target="var" test="{%Montreal%}" mode="notequals" value="{%Toronto%}">
	<echo value="Montreal is {%Montreal%}, not {%Toronto%}"/>
</IF>

If both the variable value (test=) and the testes value (value=) are numbers (integer or floating), the comparison is computed with the corresponding numbers. If one of these two values is not a number, the test is performed lexicographically:

XML
<loop list="MyList">
	<IF target="var" test="{%loopindex%}" mode="LessThan" value="3">
		<echo value="{%loopindex%} < 3 in {%listName%}"/>
	</IF>
</loop>

New test modes

XML
<SetVar MyVar="sapio365"/>
<if target="Var" Test="{%MyVar%}" mode="contains" value="pio">
	<echo value="{%MyVar%} contains pio"/>
</if>
<if target="Var" Test="{%MyVar%}" mode="notcontains" value="666">
	<echo value="{%MyVar%} does not contains 666"/>
</if>
<if target="Var" Test="{%MyVar%}" mode="Begins" value="sap">
	<echo value="{%MyVar%} begins with sap"/>
</if>
<if target="Var" Test="{%MyVar%}" mode="notBegins" value="ytria">
	<echo value="{%MyVar%} does not begins with ytria"/>
</if>
<if target="Var" Test="{%MyVar%}" mode="ends" value="io365">
	<echo value="{%MyVar%} ends with io365"/>
</if>
<if target="Var" Test="{%MyVar%}" mode="notBegins" value="montreal">
	<echo value="{%MyVar%} does not begins with montreal"/>
</if>
JavaScript errors detected

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

If this problem persists, please contact our support.