Email Script; help with a template.print statement

Brendan Hallida
Kilo Guru

Hi all,

I am trying my hand at html reporting via email notifications / scripts.   I would like to enhance what I have so far, with including a hyperlink for the ticket number.

I have this template.print which works correctly, however, does not have a clickable number link:

template.print("<tr><td>" + gr.number + "</td><td>" + gd.getDisplayValue() + "</td><td>" + gr.short_description + "</td></tr>");

I found an example in another thread as below:

template.print("<a href='" + url + "'>" + current.number + "</a>");

This does not work when I try to combine with my existing statement

template.print("<tr><td> <a href='" + baseUrl + gr.getLink() + "'>" + gr.getValue('number') + "</a></td><td>" + gd.getDisplayValue() + "</td><td>" + gr.short_description + "</td></tr>");

I get a blank screen in the email preview, so I believe that my attempt above is off a little.   Just after another set of eyes to see where I could be going wrong.

Cheers,

Brendan

  1. template.print("<a href='" + url + "'>" + current.number + "</a>");  
4 REPLIES 4

Michael Fry1
Kilo Patron

We use something like this:


template.print('Click here to view ' + tableName + ': ${URI_REF}');

Screen Shot 2017-02-16 at 6.22.11 PM.png


Hi Michael,



The code you're suggesting would only return the current ticket number?   I'm not sure that will work, as the script is referencing filtered data, as per Using Email Notifications as Custom Reports



Cheers,


Brendan


Yes, it returns the current ticket number. Works fine for us in Helsinki P7.


Hi Micahel,



Unfortunately, I cannot use it in this instance.



This is the mail script I am currently working with.   The point of the mail script is to filter data and then display it in a html table.



var gr = new GlideRecord('task');


var gd = new GlideDate();


gd.setDisplayValue(gr.sys_created_on);


gr.addEncodedQuery("active=true^sys_class_name=sc_task^ORsys_class_name=incident^sys_created_onRELATIVELE@dayofweek@ago@60^assignment_group=5f6441efc0a8010e0177fcb589156352");


gr.query();



template.print('<table class="report-table"><tr class="tr"><th class="th">Number</th><th class="th">Opened</th><th class="th">Short Description</th></tr>');



while(gr.next()){


template.print("<tr><td> <a href='" + baseUrl + gr.getLink() + "'>" + gr.getValue('number') + "</a></td><td>" + gd.getDisplayValue() + "</td><td>" + gr.short_description + "</td></tr>");


}