Tag: CalcVar

The CalcVar function lets users create a script variable that contains the result of a javascript (JS) expression.


<CalcVar/>
XML

Tag Attributes

AttributesAttribute ValuesValue DescriptionComment
Variable NameN/AAny unreserved name. Reserved names are:

Date: Current date MM/DD/YYYY
Time: HH:MM;SS AM/PM

Loop context
LoopIndex: Current loop index
ListSize: Current list size
ListName: Current list name

FolderDocuments: Windows account Documents folder path (%USERPROFILE%\Documents)
FolderTemp: Ytria temp folder path (%LOCALAPPDATA%/Ytria)

ErrorAction
ErrorSystem
N/A
Variable ValueN/A

Any string representing a valid JS expression (cf annotation comments in grid)

The value of the JS expression is:
- a text
- a number
- a boolean as text: True, False
- a date in ISO8601 format

If invalid JS code is used, the variable will receive the text of the error message. A simple arithmetic operation is a valid piece of JS: 567 + 99

It is recommended to use single quotes for strings.

N/A
PrecisionN/AIf omitted, the result is rounded to the nearest integer; otherwise specifies the number of decimals.N/A

Detailed Description

All CalcVar must comply to the JS language. All formulas are evaluated as Javascript, even very simple ones like: <CalcVar num1="665 + 1"/>

Single line formulas do not require a terminating semi-colon. Formulas with more than a single line must use a terminating semi-colon, or will end up with a syntax error.

When the return value is an array (list of values), the variable receives a semi-colon separated serialization of the array:


<CalcVar arrayNum=
"
	var a = [666, 55, 4];
	a
"
/>
XML



=> the value in variable {%arrayNum%} is: "666;5;4"

Example Script

<ytriaAutomation>
	<CalcVar arrayNum=
	"
		var a = [666, 55, 4];
		a
	"
	/>
	<CalcVar arrayString=
	"
		var a = ['taxation'.'is'.'theft']:
		a
	"
	/>
	<CalcVar arrayDate=
	"
		var a = [new date(). new Date('1000-01-01'). new Date ('1999-12-31)]:
	"
	/>
	<echo value="Numbers: {%arrayNum%}"/>
	<echo value="Strings: {%arrayString%}"/>
	<echo value="Dates: {%arrayDate%}"/>
	<CalcVar num1="665 + (1)"/>
	<CalcVar num2="-44.0 * ((1 + 50/25)/2)"/>
	<SetVar precision2="2"/>
	<SetVar precision6="6"/>
	<CalcVar result1="{%num1%} + {%num2%}"/>
	<CalcVar result2="{%num1%} - {%num2%}"/>
	<CalcVar result3="{%result1%} * {%num2%} + 88" precision="{%precision2%}"/>
	<CalcVar result4="{%result1%} * ({%num2%} + 1)" precision = "2"/>
	<CalcVar result5="{%result1%} / ({%num2%} + 2)" precision="{%precision6%}"/>
	<echo value="num1 = {%num1%}"/>
	<echo value="num2 = {%num2%}"/>
	<echo value="result1 = {%result1%} = {%num1%} + {%num2%}"/>
	<echo value="result2 = {%result2%} = {%num1%} - {%num2%}"/>
	<echo value="result3 = {%result3%} = {%result1%} * {%num2%} + 88 (precision {%precision2%})"/>
	<echo value="result4 = {%result4%} = {%result1%} * ({%num2%} + 1) (precision 2)"/>
	<echo value="result5 = {%result5%} = {%result1%} / ({%num2%} + 2) (precision {%precision6%})"/>
</ytriaAutomation>
XML