Message scripting

Learn about scripted templates and script context that are needed for message
scripting.

Transact email message scripting requires two components to render a complete email ready for sending.

  • Scripted template: An HTML document that contains both static HTML markup and the scripting code inside what are often described as mustaches {{ … }}.
  • Script context: 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.

Table 1. Comparing personalization field formats for context data
JSON Transact 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

View an example of a scripted template that is used in message scripting.

Example

Add a scripted template 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.

Transaction XML with JSON Script Context

<XTMAILING>
    <CAMPAIGN_ID>4503824</CAMPAIGN_ID>
    <RECIPIENT>
        <EMAIL>watson@silverpop.com</EMAIL>
        <BODY_TYPE>HTML</BODY_TYPE>
        <SCRIPT_CONTEXT><![CDATA[
           {"first": "Watson",
           "country": "Canada",
           "favnum":"2"
           }
        ]]> 
        </SCRIPT_CONTEXT>
    </RECIPIENT>
</XTMAILING>

Equivalent Transaction XML with Standard Personalization

<XTMAILING>
    <CAMPAIGN_ID>4503824</CAMPAIGN_ID>
    <RECIPIENT>
        <EMAIL>watson@silverpop.com</EMAIL>
        <BODY_TYPE>HTML</BODY_TYPE>
        <PERSONALIZATION>
           <TAG_NAME>first</TAG_NAME>  
           <VALUE>Watson</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 Watson ,<br/> 
You are from Canada.<br/> 
</body></html>

Join The Discussion

Your email address will not be published. Required fields are marked *