EscapeVar: Escape variable value for Javascript or XML compatibility

Tag: EscapeVar

The action EscapeVar function assigns a value to a variable (like SetVar) after having escaped its value according to target platform.

EscapeVar can process several variables at once

Detailed Description

Javascript (JS) and XML formulas assigned to a variable need to be escaped to be compatible with the interpretation engine. 

Tag Attributes

Attributes

Value Description

Variable Name

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

Variable Value

Any string or number to escape

CRLF

Replacement for CR,,LF or CRLF. If not supplied, CR and LF will be removed

Type

Target platform type - Required
Accepted values:
JS
XML

Example Scripts

XML
<EscapeVar ESCAPEDtext="{%FormattedText%}" Type="JS"/>
XML
<ytriaAutomation>
	<CalcVar FormattedText='USE_CDATA'>
		<![CDATA[
		var str = '\tName\n\tValue\n\tType\n\n';
		str;
		]]>
	</CalcVar>
	<Echo Value="FormattedText: {%FormattedText%}"/>
	<EscapeVar ESCAPEDtext="{%FormattedText%}" Type="JS"/>
	<CalcVar JSCalculated='USE_CDATA'>
		<![CDATA[var str = '{%ESCAPEDtext%}' + '\tConvoy 2022\n\n';
		str;]]>
	</CalcVar>
	<Echo Value="Returned from JS: {%JSCalculated%}"/>
	<!--CalcVar v_ErrorText='USE_CDATA'>
		<![CDATA[
		rgx = /\[.*\]:\n([^\n]*\n).*/gs;
		var str = `{%ErrorAction%}`;
		rgx.exec(str)[0];
		]]>
	</CalcVar>
	<Echo Value="{%v_ErrorText%}"/-->
</ytriaAutomation>