Loading

Email Templates

From ServiceNow Wiki
Home > Script > Server Scripting > Email Templates
Jump to: navigation, search
Notifications
Knowledge.gif Get the Book

Contents

1 Overview

Email templates enable administrators to create reusable content for the subject line and message body of email notifications. Templates deliver consistent information on specific system activities and improve the efficiency of creating multiple email notifications for similar actions. If necessary, you can make minor changes on the fly to an email that uses a template by overriding the subject line and message body content in the notification form. A common practice is to define the message body in a template and create new subject lines for different types of recipients. There is no limit to the number of templates that you can create.

Email templates are created in rich HTML format, and administrators have the option of converting existing email templates to rich HTML (starting with the Eureka release). This format provides several advantages, including:

  • Raw HTML content is converted into a WYSIWYG format.
  • The content can be edited in a feature-rich HTML editor.
  • Mail scripts are condensed into a single, easy-to-read line that can be reused in multiple email notifications.
  • To prevent broken links, images linked using URLs relative to a particular instance are converted to absolute links.

2 Creating a Template

This section provides instructions for creating a template with rich HTML formatting, which is available starting with the Eureka release. If you are using an earlier version, see the previous version information.

  1. Navigate to System Policy > Email > Templates.
  2. Click New.
  3. Fill in the fields, as appropriate (see table).

Change Risk Template Callout.png

Field Description
Name Enter a unique name for the template. For example, change.update.risk.
Table Select the name of the table involved. For example, Change Request [change_request].
Subject Enter a subject line that explains the purpose of the email. Select the appropriate variables for the subject line from the fields available on the selected table. Place the cursor where you want the variable to appear, and click the field name in the Select variables column. For example:
${sys_class_name} ${number} with ${risk} risk has been assigned to you.
Message HTML Enter the content of the email template message. You can use the HTML editor toolbar to format the HTML, and you can include variables from the Select variables column. Variables map to column names available from the notification table, its parent tables, and reference tables. Use variables to include values from a record in the table such as an incident's short description or comments and work notes.

Notes:

Message Text Enter the notification message to send in plain text.

Note: When a template is applied to a notification, the contents of this field are used if you selected HTML and plain text or Text in the Content Type field in the Email Notification form.

SMS alternate Create a different message to be delivered to the recipient's SMS device. You might want a brief message, showing the most important information only. If this message field is blank, the contents of the Message Text field are used for the SMS message.

Note: The message in this field is used when the message is sent to a device configured as SMS.

2.1 Applying a Template to an Email Notification

If you are using an earlier version, see the previous version information.

  1. Navigate to System Policy > Email > Notifications.
  2. Open the email notification record that should use the template.
  3. Navigate to the What it will contain section.
  4. From the Email template field, select the appropriate template.
  5. Click Update.

2.2 Overriding a Template Value

You can customize an email notification to override a specific value without changing the basic information contained in the template, starting with the Dublin release. If you are using a version prior to Dublin, see the previous version information.

  1. Navigate to System Policy > Email > Templates.
  2. Open an email template.
  3. Enter a new value for the field you want to override.
    For example, you might change the subject line to read The risk level of ${sys_class_name} ${number} has been raised to ${risk}. This would not change the basic information about the change request contained in the template, but would make the email notification appropriate for the change manager who needs to know when risk levels are escalated above a certain threshold.
  4. Click Update.

2.3 Creating Templates in Versions Prior to Eureka

3 Working with Existing Email Templates

New email templates are created in the rich HTML format (starting with the Eureka release). You can convert template content that was created in a pre-Eureka version to rich HTML so it can be edited in the WYSIWYG editor.

To convert an email template to rich HTML:

  1. Navigate to System Policy > Email > Templates.
  2. Open the email template you want to convert.
    Template not converted.png
  3. Click Switch to Rich HTML Editor.
    When content is converted, these changes are made to the content:
    • HTML Editor: Any raw HTML in the Message field is rendered as WYSIWYG text in the Message HTML field. The content can be edited in a feature-rich HTML editor.
    • Simplified Mail Scripts: Any mail scripts in the body are automatically saved to the Email Script [sys_script_email] table and are replaced in the notification body with an embedded script tag. This makes the template body easier to read and makes it easier to reuse scripts in multiple email templates.
    Template converted.png
  4. Modify the message text, as needed, using the WYSIWYG editor or by editing the underlying HTML.
Note
Note: The letter "P" at the bottom of the screen shows the location of your cursor within the Message field. In this case, the cursor is in a line containing an HTML <p> tag.
Note
Note: Email templates that are already formatted with rich HTML do not show the Switch to Rich HTML Editor button.


3.1 Best Practice for Creating Templates

Whether you are working with templates converted from earlier versions of ServiceNow or creating new templates in the rich HTML format, it is a best practice to write mail scripts in System Policy > Email > Notification Email Scripts. When the scripts are completed, a ${mail_script:script name} embedded script tag should be added to the email template body. This makes it easy to use the same scripts in multiple email templates. All that needs to be copied and pasted from one template to the next is the embedded script tag.

If you manually enter a mail script in the body of a new or converted email notification or template, and then attempt to save the record, a message asks whether the mail script should be converted. Unconverted mail scripts often fail to run from inside the HTML editor. If you select Yes, the script is added to the Email Script [sys_script_email] table and is automatically replaced in the body with an embedded script tag.

You can view the mail scripts in their original form by opening the email template and clicking the Show Notification Scripts related link.

4 Calendar Integration

With email notifications, you can use import export maps to leverage information about records and integrate with Outlook or another calendar. For example, an email notification can create a calendar event based on the planned start and end dates of a change request. To integrate with a calendar, add one or more of the following iCalendar variables to an email template message and reference the email template from the notification. The variables must be added to the Message Text field starting with the Eureka release.

Variable Name Description
${dtstart} Start Date
${dtend} End Date
${location} Location
${alarm_time} Alert or reminder time
Note
Note: In order for the calendar integration to work, iCalendar variables must be added to an email template. The integration does not work if the variables are added directly to the email notification.


ServiceNow computes the value of iCalendar variables using import and export maps for the following tables:

  • change_request
  • reminder
  • itil_appointment
  • incident
Import export maps

Each import export map can specify a different set of iCalendar fields. For example, the icalendar.change_request import export map only maps two iCalendar fields.

Sample mappings for the dtstart and dtend variables

ServiceNow uses the External Name as the variable name in the email template. For example, the icalendar.change_request import export map defines the dtstart and dtend variables.

External Name Associated Variable Name Table Field Mapped Field Label
dtstart ${dtstart} change_request start_date Planned start date
dtend ${dtend} change_request end_date Planned end date

4.1 Creating Custom Mappings to iCalendar Fields

If you want to generate iCalendar invitations that use values from custom tables, you must create an import export map that computes the values of the iCalendar fields.

  1. Create the custom table and fields for the email template.
    Use the Date/Time (glide_date_time) field type for fields that will map to the ${dtstart} and ${dtend} variables.
  2. In the navigation filter, enter sys_impex_map.list.
  3. Filter the list on [Type] [is] [icalendar].
  4. Click New.
  5. For Name, use the following naming convention: icalendar.[table name]. For example, icalendar.u_my_custom_table.
  6. Right-click the form header and click Save.
  7. In the Field Maps related list, click New.
  8. In the Mapping Entry Wizard, select Mapping to a Database Field.
  9. Create field mappings for the iCalendar fields you want to use. For example, map the External Name dtstart to the u_meeting_start_time field in the u_my_custom_table table.
    Sample field mapping dtstart

  10. Click Submit.
  11. Repeat steps 7 through 9 for each iCalendar field you want to map.
  12. Click Update.


Here are sample field mappings between iCalendar variables and custom fields in a custom table:

External Name Database Field Type Map Table
dtstart u_meeting_start_time field icalendar.u_my_custom_table u_my_custom_table
dtend u_meeting_end_time field icalendar.u_my_custom_table u_my_custom_table
location u_meeting_location field icalendar.u_my_custom_table u_my_custom_table
Was this article helpful?
Yes, I found what I needed
No, I need more assistance
Views
Personal tools