Message Scripting

Transact email message scripting requires a scripted template as well as script context to render a complete email that is ready for sending.
A scripted template is an HTML document that contains both static HTML markup and the scripting code inside what are often described as mustaches {{ … }}. Script context is data that is provided to the script that renders the template's dynamic results. We recommend that you use JSON personalization fields in the script context.

JSON versus standard Transact XML personalization fields

You can use standard Transact XML personalization fields to provide the script context for many kinds of email templates. However, JSON is the preferred format. This format can be used in more complex templates, such as layouts that involve nested data or looping, and is a flexible way to model data to match the layout of even the most sophisticated templates.

The table below compares personalization field formats for context data.

JSONTransact XML
Data is not saved to the Transact database custom columns.

Can provide a value as a number.

You can provide JSON and XML personalization fields if you want the data saved in the Transact database custom columns.
Data is saved to the Transact database custom columns.

Cannot provide a value as a number.

Script context fields

The following fields are available in the script context:

  • MAILING_ID: The active Mailing ID for the group of automated messages.

  • FORWARD_INFO: Always set to an empty string.

  • JOB_ID_CODE: The encoded version of the Job ID. In Transact, this is the same as the Report ID.

  • RECIPIENT_TYPE: Always set to zero.

  • RECIPIENT_ID: The URL-encoded version of the encoded Recipient ID.

  • RECIPIENT_CODE:

  • mailing tracking level unique: The URL-encoded version of the encoded Recipient ID.

  • mailing tracking level unique: Set to zero.

  • OPT_OUT_VERP: the value based on the Mailing ID, Recipient ID, Job ID, and sending opt-out domain.

Scripted template example

When a scripted template is added to the transactional email, the email recipient sees the scripted template in the message body.

<html>
	<header>
		<title></title>
	</header>
	<body>
Hello {{first}},
		<br/>
{{#if country }}
You are from {{country}}.
		<br/>
{{else if favnum}}
I don't know where you are from, but your favorite number is {{favnum}}.
{{else}}
Sorry, I don't know where you are from or what your favorite number is.
{{/if}}
	</body>
</html>

Script context examples

Compare examples of script contexts that are used in message scripting and view the output.

<XTMAILING>
	<CAMPAIGN_ID>4503824</CAMPAIGN_ID>
	<RECIPIENT>
		<EMAIL>[email protected]</EMAIL>
		<BODY_TYPE>HTML</BODY_TYPE>
		<SCRIPT_CONTEXT>
			<![CDATA[
           {"first": "Winston",
           "country": "Canada",
           "favnum":"2"
           }
        ]]>
		</SCRIPT_CONTEXT>
	</RECIPIENT>
</XTMAILING>
<XTMAILING>
	<CAMPAIGN_ID>4503824</CAMPAIGN_ID>
	<RECIPIENT>
		<EMAIL>[email protected]</EMAIL>
		<BODY_TYPE>HTML</BODY_TYPE>
		<PERSONALIZATION>
			<TAG_NAME>first</TAG_NAME>
			<VALUE>Winston</VALUE>
		</PERSONALIZATION>
		<PERSONALIZATION>
			<TAG_NAME>country</TAG_NAME>
			<VALUE>Canada</VALUE>
		</PERSONALIZATION>
		<PERSONALIZATION>
			<TAG_NAME>favnum</TAG_NAME>
			<VALUE>2</VALUE>
		</PERSONALIZATION>
	</RECIPIENT>
</XTMAILING>

Resulting HTML

The contexts generate the same HTML results.

<html>
	<header>
		<title></title>
	</header>
	<body> 
Hello Winston ,
		<br/> 
You are from Canada.
		<br/>
	</body>
</html>