- 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-17-2016 02:18 PM
Have you tried this
${task.URI} or ${task.URI_REF}
Assuming your notification is on the Task SLA table.
Scripting for Email Notifications - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 02:29 PM
Will that work in a script? "var link = ${task.URI};"? The script syntax checker doesn't seem to like it. I need to actually pull in the url to be used in the script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 02:33 PM
Sorry, wasn't aware you wanted this in a script. Why script when you can get the link via a shortcut?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 07:21 AM