Directing Users to the Service Portal: Embedding Hyperlinks in ServiceNow Email Notifications
- nathanlee142
- Mar 21
- 4 min read
Updated: Apr 5

In today's digital landscape, efficient communication is paramount. For ServiceNow users, email notifications play a vital role in keeping them informed about the status of their requests, incidents, and other important records. A key aspect of these notifications is the ability to provide direct links back to the relevant record within the ServiceNow Service Portal. This allows end-users to quickly access the information they need without having to navigate through the portal. This article will guide you through the process of embedding direct hyperlinks to Service Portal records within your ServiceNow email notifications, enhancing user experience and streamlining workflows.
Imagine a scenario where an end-user reports an incident through the Service Portal. They receive an automated email notification confirming the creation of the incident. To check the status or add more information, the user needs a quick and easy way to return to their specific incident within the portal. Simply providing the instance URL is insufficient; the link should take them directly to their record.
The Challenge: Linking Directly to Service Portal Records
While ServiceNow's email notifications offer various ways to include links, directly linking to a specific record in the Service Portal requires a slightly different approach compared to linking to the platform's backend interface. The Service Portal utilizes a specific URL structure that includes parameters for the portal page, table, and the record's unique identifier (sys_id).
The Solution: Utilizing a Mail Script for Dynamic Hyperlinks
The most effective method to create these direct Service Portal links in email notifications is by using a ServiceNow Mail Script. Mail Scripts allow you to write server-side JavaScript code that can be executed when an email notification is generated. This script can dynamically construct the correct Service Portal URL based on the record the notification is related to.
Here's a step-by-step guide on how to create and use a Mail Script to achieve this:
Navigate to System Policy > Email > Notification Email Scripts.
Click "New" to create a new Mail Script.
Give your Mail Script a descriptive name. For example, "service_portal_ticket_link." The "Script" field will auto-populate with the prefix mail_script: followed by the name you provide. This is how you will reference the script in your notifications.
Paste the following code into the "Script" field:
JavaScript
(function runMailScript(
/* GlideRecord / current, / TemplatePrinter / template,
/ Optional EmailOutbound / email, / Optional GlideRecord / email_action,
/ Optional GlideRecord */ event) {
var portalURL = gs.getProperty('glide.servlet.uri') + 'sp?id=ticket&table=' + current.sys_class_name + '&sys_id=' + current.sys_id;
var linkText = current.number; // You can customize the link text here var hyperlink = '<a href="' + portalURL + '">' + linkText + '</a>';
template.print(hyperlink);
})(current, template, email, email_action, event);
Explanation of the Code:
gs.getProperty('glide.servlet.uri'): This retrieves the base URL of your ServiceNow instance.
'sp?id=ticket&table=' + current.sys_class_name + '&sys_id=' + current.sys_id: This constructs the Service Portal URL.
sp?id=ticket: This part specifies the "Ticket" page within the Service Portal (this might vary depending on your portal configuration).
table= + current.sys_class_name: This dynamically gets the table name of the current record (e.g., incident, sc_request).
sys_id= + current.sys_id: This dynamically gets the unique identifier of the current record.
current.number: This retrieves the display number of the current record (e.g., INC00123, REQ00456) and uses it as the link text. You can customize this to display other relevant information.
'<a href="' + portalURL + '">' + linkText + '</a>': This creates an HTML hyperlink using the generated URL and the specified link text.
template.print(hyperlink): This prints the generated HTML hyperlink into the email notification.
Click "Submit" to save your Mail Script.
Now, you can reference this Mail Script in your Email Notifications. Open the email notification you want to modify.
In the "Message body" of the notification, use the following syntax to include the hyperlink:
${mail_script:service_portal_ticket_link}
Replace service_portal_ticket_link with the actual name you gave to your Mail Script.
Practical Examples and Use Cases:
Incident Notifications: In notifications related to new or updated incidents, this Mail Script will generate a direct link to the incident record in the Service Portal.
Request Notifications: For service catalog requests, you can use the same script, and it will automatically link to the correct request record due to the dynamic nature of current.sys_class_name. You might need to adjust the sp?id= parameter if your request page has a different ID. For example, it might be sp?id=sc_request.
Task Notifications: This method can be applied to any table with a corresponding Service Portal page, such as change requests or problem records.
Customizing the Link Text:
You can easily modify the linkText variable in the Mail Script to display different information. For example, instead of the record number, you could display the short description:
JavaScript
var linkText = current.short_description;
Alternative Solutions:
While Mail Scripts offer the most flexibility, some basic links can be created using the ${URI} formatter in your email notifications. However, this often directs users to the backend interface rather than the Service Portal. For consistently directing users to the portal with dynamic record links, Mail Scripts are the recommended and most reliable approach.
Conclusion
Embedding direct hyperlinks to ServiceNow Service Portal records within email notifications significantly enhances the user experience by providing quick and easy access to relevant information. By utilizing Mail Scripts, you can dynamically generate the correct URLs, ensuring that users are taken directly to their specific records within the portal. This streamlined approach improves efficiency and empowers end-users to stay informed and take necessary actions with ease. The next step is to implement this Mail Script in your relevant ServiceNow email notifications to provide your users with seamless access to their records in the Service Portal.