- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 02:15 PM
I'm setting up an email notification based on an SLA, and I need to grab the SLA's parent task url for a variable in the script. Does anyone know an easy way to do this? Using "var link = current.getLink();" just gets a url for the SLA record not its parent task, and using "var link = current.task.getLink();" doesn't seem to work. Since I need the url brought in as a script variable I don't think the built in ${URI} or ${URI_REF} tags will work. I'm sure there's an easy answer to this that I just can't find.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2016 09:49 AM
So I actually figured out a workaround for this. I'm posting it here in case it's useful to anyone else. I'm still not sure why "current.task.getLink()" won't work to grab a link to the sla's task record, but "current.task.sys_id" WILL work to grab the sys id of the sla's task record. With that knowledge I changed the script to use the task sys id to make a link in the script. The particular version of the script here will only work for records extended off the task table, but that should include most records that would have SLA's running on them.
(function runMailScript(current, template, email, email_action, event) {
var link = current.task.sys_id;
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;';
template.print('<br><font face="helvetica">');
template.print('<a href="' + gs.getProperty('glide.servlet.uri') + 'task.do?sys_id=' + link + '"');
template.print('style="' + backgroundColor + border + color + fontSize + fontFamily + textDecoration + webKitBorder + mozBorder + display + padding);
template.print('">');
template.print(gs.getMessage('Take me to the Ticket'));
template.print('</a>');
template.print('</font>');
})(current, template, email, email_action, event);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 07:24 AM
Via mail script:
current.task.getLink()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 07:32 AM
Good call Kalai!
FYI - if you reference the example in section 9.11 of the GlideRecord wiki page, you can leave off the gs.getProperty() part.
The email system (as of Eureka) is now smart enough to convert relative paths to fully qualified URLs. Ex: href="/incident.do?sys_id=12345" will automatically be translated to href="https://myincident.service-now.com/inicdent.do?sys_id=12345". No need to build your own URL piece by piece any more.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 07:42 AM
I've tried "current.task.getLink()". Unfortunately, that ends up generating a link to "https://<instance>.service-now.com/undefined".

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 07:47 AM
Hi Chase,
What table is your notification running on? Can you send a screenshot of your notification definition record? I feel like we are missing something?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 08:05 AM
The funny thing is we haven't really made any major customizations. It's the OOB SLA notifications "SLA warning" & "SLA breached". Both run on the task_sla table. All I've done customization wise is duplicate and modify the OOB "incident_take_me_to_the_incident" email script that's in Helsinki and call it in the SLA notifications.
So here's the OOB script:
(function runMailScript(current, template, email, email_action, 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="' + link + '"');
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);
and here's the script I'm trying to use:
(function runMailScript(current, template, email, email_action, event) {
var link = current.task.getLink();
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;';
template.print('<br><font face="helvetica">');
template.print('<a href="' + link + '"');
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>');
})(current, template, email, email_action, event);
I simply removed the if statements I didn't need, and changed the link variable to "current.task.getLink();". I hoped it'd be a straightforward modification, but it doesn't seem to be.