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

bitkid
Giga Contributor

I believe that the correct answer is, that "current" is an object of GlideRecord but current.task is a reference.



You can use the getLink function if you load the task as an object:



var task = new GlideRecord('task');


task.get(current.task);


var link = task.getLink();



-- Jannik Nielsen


bitkid
Giga Contributor

And now that I'm 3 years smarter I would do it differently:

 

current.task.getRefRecord().getLink();