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).


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

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

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

Variables can use other variables

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

Loop context

	<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%}"/>

Variable test with IF

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

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

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:

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

New test modes

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

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

If this problem persists, please contact our support.