OBLYTECH Logo
OBLYTECH Logo

Email Template in ServiceNow: Create and Edit with Variables

A ServiceNow email template stores the subject line and message body for a notification so several notifications can reuse them. You create one from All, System Notifications, Email, Templates by selecting New, choosing a table, writing the subject and Message HTML with variables such as the record number, then selecting the template on the notification.

What an email template holds

A template defines a subject line and a message body, and the body can exist in more than one form: rich HTML, plain text, and a short alternate for SMS devices. The point is reuse: write the wording once and let notifications share it. The wider practice is covered in notifications and email handling best practices.

You can build a template with rich HTML formatting rather than plain text only. The form gives you an HTML editor toolbar for formatting.

Create a template step by step

You need the admin role. Open the Templates list under System Notifications, then Email, and select New. The form asks for the following.

Field What to enter
Name A unique name, for example change.update.risk
Application The type of scoped application the template belongs to
Email layout A predefined layout, if the body should sit inside shared content
Table The table involved, such as Change Request
Subject A line that explains the purpose of the email
Message HTML The formatted body
Message Text The plain-text body
SMS alternate A short message carrying the key information

Choose the Table first. Variables map to column names from the notification table, its parent tables and its reference tables, so the table you pick decides which values you can drop into the message.

Write the subject

Put the cursor where a value should appear, then click the field name in the Select variables column. The system inserts the variable for you. A subject built this way can combine the record class, the number and the risk value, followed by a plain sentence saying the record has been assigned to the recipient.

Write the Message HTML

The Message HTML field takes the formatted body. Use the toolbar to format the content and the Select variables column to add values. Since variables can come from parent and reference tables as well as the notification table, a body can include fields from related records without any code.

One limit matters when you design the message: you cannot use HTML to style the ${comments} variable.

Fill in Message Text and SMS alternate

Message Text holds the notification message in plain text. SMS alternate creates a different message for an SMS device. Keep it brief and put only the key information in it. If you leave SMS alternate blank, the Message Text content is used for SMS messages.

How the template reaches a message

The notification decides which parts of the template are used, through its Content type setting:

  • Message HTML is used when the Content type is HTML and plain text, or HTML.
  • Message Text is used when the Content type is Text, or HTML and plain text.

This matters when a template seems to ignore something you wrote. If you filled in Message Text but the notification sends HTML only, the plain-text body never appears. Check the Content type on the notification before assuming the template is broken. If the email never arrives at all, the diagnostic steps for email notifications not sending cover a different set of causes.

Variables you can use in a template

Variables use the syntax ${variable-name+variable-parameters}. The variable name is always required. Most parameters are optional, and not all variables support them.

Variable Result
${field-name} The value of the specified field
${image-field-name} An image associated with a record, typically used with HTML to set the source of an image element
${URI} A link to the current record, with the link text LINK
${URI_REF} A link to the current record, with the record’s display value as the link text
${reference-field.URI} A link to the record listed in a reference field
${reference-field.URI_REF} The same link, using the referenced record’s display value as the text
${CMS_URI} A link to a record within a CMS page; takes the relative path as CMS site and CMS page
${notification:body} The body contents of an email template or email notification
${mail_script:script-name} Runs the specified mail script
${NOTIF_UNSUB} A link to unsubscribe from the notification
${NOTIF_PREFS} A link to set notification preferences
${comments:n} The most recent n comments made on the target record
${comments_and_work_notes:n} The most recent n comments and work notes on the target record

Parameters change what the reader sees. ${URI} and ${URI_REF} accept any valid sysparm URL parameter, such as sysparm_view or sysparm_scriptlet. A view parameter is the natural way to send a recipient to the record in the view they should use. ${NOTIF_UNSUB} and ${NOTIF_PREFS} take a link_text parameter, written in quotation marks, which sets the words shown as the link.

Comment counts are simple to control. The number after the colon must be greater than 0. ${comments:3} shows the last three comments, and ${comments} on its own shows all of them. The same pattern applies to ${comments_and_work_notes}.

Dot-walking reaches related records. Following a reference field with .URI or .URI_REF links to the record the field points to, rather than to the record that triggered the notification.

Workspace is a special case. These link variables do not apply to records in Workspace. The route for those records is a mail script that prints a URL to the notification.

Reuse the body design with an email layout

When many templates should share one design, put that design in an email layout and select it in the template’s Email layout field. The HTML from the layout then shows in the body of any template that uses it.

You need the admin role and an existing email template. Open All, then System Policy, then Email, then Layouts, select New and complete the form:

  • Name: a unique name for the record.
  • Application: the parent application the record belongs to.
  • Description: optional.
  • Advanced: select whether to display the Advanced Layout field.
  • Layout: an inline editor for adding HTML elements. You can insert notification variables to pull in values from the related record.
  • Advanced Layout: a field for entering HTML by hand. To type in it, first use the link that disables syntax highlighting and script formatting.

Submit the layout. Then open the email template that should use it, choose the layout in the Email layout field and select Update.

Inside a layout, the ${notification:body} variable specifies where the body content of the template or notification is displayed. Put it where the main message should land, with the shared surrounding content placed around it in the layout.

Add logic with a mail script

A variable inserts a value. A mail script runs code when the content depends on conditions or on records beyond the one that triggered the notification.

Mail scripts are created in System Notifications, then Email, then Notification Email Script. Call one from a template or notification with ${mail_script:script name}, using the name you gave the script.

The simplest example is a text string. A script that calls template.print(“Incident number – ” + current.number) writes a line such as Incident number – INC00001 into the message. The script reads the record’s number through current.number.

Larger examples go further:

  • One adds links to attachments, using the instance_name property through gs.getProperty so the notification still works when the content moves between instances.
  • One reads the watch list, splits it on commas, queries user records that have an email address and a notification setting, and adds each user’s email as a copied recipient.

For copied and blind copied recipients, use the email object inside the script. For mail that comes in rather than goes out, see inbound email actions. Calling email.addAddress with the type “cc”, then an address and a display name, adds a CC recipient, and the same call with “bcc” adds a blind copy.

Edit an existing template safely

To change a template, open it from the Templates list and edit the same fields you used to create it. Because several notifications can point to one template, a single change can reach many of them. Two habits reduce the risk, and the testing and acceptance checklist for notifications adds more checks:

  1. Before saving, find the notifications that use the template, so you know which messages your change will alter.
  2. After saving, trigger a test record and read the email that arrives. Check the subject, the links and the plain-text version, not only the formatted one.

Frequently asked questions

Where do I create an email template in ServiceNow?

Open the Templates list under System Notifications, then Email, and select New. The admin role is required.

What is the difference between Message HTML and Message Text?

Message HTML is the formatted body, used when the Content type is HTML and plain text, or HTML. Message Text is the plain-text body, used when the Content type is Text, or HTML and plain text.

How do I put the record number in the subject?

Place the cursor in the Subject field, then click the field name in the Select variables column. The variable for that field is inserted.

How do I add a link to the record in the email?

Use ${URI} for a link with the text LINK, or ${URI_REF} for a link that uses the record’s display value as its text. Neither applies to records in Workspace, where a mail script that prints a URL is the route.

What happens if SMS alternate is blank?

The Message Text content is used for SMS messages.

What does ${notification:body} do?

It specifies where the body contents of a template or notification are displayed inside an email layout.