Message scripting

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

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.
    • 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.


Add a scripted template to the transactional email. The email recipient sees the scripted template in the message 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}}.
Sorry, I don't know where you are from or what your favorite number is.

Script context examples

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

Transaction XML with JSON Script Context

           {"first": "Watson",
           "country": "Canada",

Equivalent Transaction XML with Standard Personalization


Resulting HTML

The contexts generate the same HTML results.

Hello Watson ,<br/> 
You are from Canada.<br/> 

Join The Discussion

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

Privacy Preference Center

Close your account?

Your account will be closed and all data will be permanently deleted and cannot be recovered. Are you sure?