- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2016 05:54 PM
Hi all,
We would like to have emails going to the end users contain the portal link to their request / incident. I am using email notifications.
The actual link that we have is the following:
Incident:
http://<instance>.service-now.com/sp?id=ticket&table=incident&sys_id=22b899754f112240f5333d501310c786
Request:
http://<instance>.service-now.com/sp?id=sc_request&table=sc_request&sys_id=9350c9f14fddee00f5333d501310c715
I have been doing some research, and found a lot pointing towards this wiki entry: Scripting for Email Notifications - ServiceNow Wiki
That entry has helped my understanding, however it is old and is referring to the ESS page.
With the code that it suggests, it seems to always add incident.do?sysparm_document_key=incident in the code.
For example:
${CMS_URI+sp?id=ticket&table=incident}
https://<instance>.service-now.com/sp?id=ticket&table=incident.do?sysparm_document_key=incident,619dac624f09ea00f5333d501310c769
I know that I am missing something, hopefully someone out there can easily identify it.
Thanks in Advance!
Brendan
Solved! Go to Solution.
- 20,011 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2016 04:27 PM
In our own instance I included Service Portal links by using an email notification script, the contents of which looks like:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var url = '<a href="' + gs.getProperty('glide.servlet.uri') + 'sp?id=ticket&table=' + current.sys_class_name + '&sys_id=' + current.sys_id + '">Link</a>';
template.print(url);
})(current, template, email, email_action, event);
I can then reference this in email notifications/templates by: ${mail_script:service_portal_link}
Note: The syntax highlighting looks a little off in the code snippet above, but you get the idea. I also replaced the name of our portal with "sp" to remain consistent with your example above.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2018 07:47 AM
Hi everyone,
This was a wonderful starting place for getting my script to work. Essentially, I didn't want to 'interrupt' the visual look my users have been accustomed to. I wasn't even aware that the link originally was sending them to the back-end instead of the SP, which SN should have accommodated for if you utilize the SP...but anyways...I wanted the exact same look as how it originally was, but to take them to the sp instead. So this is what worked for me:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var link = current.getLink();
if (email_action.name != "Incident Resolved") {
template.print('<p><font size="3" color="#808080" face="helvetica">');
template.print(gs.getMessage('You can view all the details of the incident by following the link below') + ':');
template.print('</font></p>');
}
else {
template.print('<p><font size="3" color="#808080" face="helvetica">');
template.print(gs.getMessage('If you feel the issue is not resolved, please click the following link and reopen your incident') + ':');
template.print('</font></p>');
}
template.print('<font face="helvetica">');
var backgroundColor = 'background-color: #278efc;';
var border = 'border: 1px solid #0368d4;';
var color = 'color: #ffffff;';
var fontSize = 'font-size: 16px;';
var fontFamily = 'font-family: Helvetica, Arial, sans-serif;';
var textDecoration = 'text-decoration: none; border-radius: 3px;';
var webKitBorder = '-webkit-border-radius: 3px;';
var mozBorder = '-moz-border-radius: 3px;';
var display = 'display: inline-block;';
var padding = 'padding: 5px;';
if (email_action.name == "Incident Survey") {
color = 'color: #343d47;';
backgroundColor = 'background-color: #e6e8ea;';
border = 'border: 1px solid #bdc0c4;';
}
template.print('<a href="' + gs.getProperty('glide.servlet.uri') + 'sp?id=ticket&table=' + current.sys_class_name + '&sys_id=' + current.sys_id + '"');
template.print('style="' + backgroundColor + border + color + fontSize + fontFamily + textDecoration + webKitBorder + mozBorder + display + padding);
template.print('">');
template.print(gs.getMessage('Take me to the Incident'));
template.print('</a>');
template.print('</font>');
template.print('<br><br>');
template.print('<p><font size="3" color="#808080" face="helvetica">');
template.print('Thank you.');
template.print('</font></p>');
})(current, template, email, email_action, event);
-Basically search for "notification email scripts" in navigator (I'm on Jakarta)
-Create new
-Name it service_portal_link
-Paste my code
-Save
-Go through all incident notifications and swap out ${mail_script:incident_take_me_to_the_incident} for ${mail_script:service_portal_link} - ***RECOMMENDED TO ONLY DO THIS FOR END-USER EMAIL NOTIFICATIONS AND NOT ONES GOING TO WORKERS/TECHNICIANS - LEAVE ${mail_script:incident_take_me_to_the_incident} IN THOSE NOTIFICATIONS
-Save
-Preview the notification and click the button "take me to the incident"
-Profit 😉
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 07:19 AM
Hello @dhasselquist !
I want to access the email notification from Service portal, impersonated with "assigned to" user in the incident, when the priority of the incident changes. I tried your code but its not working, may be i did something wrong.
Can please you help me with that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2019 11:23 PM
Hi I used this script and it works! One thing I noticed is that it changes the UI of the portal view once I clicked the link. How can I maintain the original view of portal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2019 01:35 AM
I used the script to have a link for portal ticket numbers.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var instance = gs.getProperty("instance_name");
var url = "https://" + instance + ".service-now.com/* CHANGE THIS TO PORTAL NAME or URL WHERE TICKET IS PLACED*" + "&sys_id="+ current.incident;
template.print('<a href="' + url + '">${incident.number}</a>');
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2020 01:56 PM