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
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
<EscapeVar ESCAPEDtext="{%FormattedText%}" type="JS"/>
<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>