Linking to SLA's Parent Task Record

chaselong
Mega Expert

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.

1 ACCEPTED SOLUTION

chaselong
Mega Expert

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);


View solution in original post

16 REPLIES 16

Chuck Tomasi
Tera Patron

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


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.


Sorry, wasn't aware you wanted this in a script. Why script when you can get the link via a shortcut?


I'm trying to make some formatting changes to the email that require scripting similar to the way Helsinki displays links to incidents in email notifications now.



Here's the Helsinki OOB example.


Capture.PNG