Skip to main content
Skip table of contents

EscapeVar: Escape variable value for Javascript or XML compatibility

Tag: EcapeVar

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

AttributesValue Description
Variable NameAny unreserved name valid in XML. Reserved names are listed on: Variables
Variable ValueAny string or number to escape
CRLFReplacement for CR,,LF or CRLF. If not supplied, CR and LF will be removed
TypeTarget 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>
JavaScript errors detected

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

If this problem persists, please contact our support.