Insert a link to an Incident in my Survey Email Notifications

iDNS
Tera Expert

Hi,

I am trying add some fields to a o insert a Survey Notification email link the user gets upon Incident Closure & that link should login user via SSO & open up in Service Portal for a user when they click on the link.

I managed to add the fields I was able to get from the XML of an Survey Trigger ID but unable to add the Link to Incident.

If I add a link such as below it completely stops printing all variables.

htmlContent += 'Link to Incident: /sp?id=ticket&table=incident&sys_id='+ sys_id+' ' +'<br />'+'<br />';

Below is a copy of my Email Notification code that works but not for Incident Link. If I add the above line it just quits. I must be missing something silly. Can you one guide me in the right direction. Thanks in Advance

var htmlContent = '';

htmlContent += '<html>';

htmlContent += '<head>';

var gr = new GlideRecord('incident');

gr.get(current.trigger_id);

htmlContent += 'We are always looking to improve our service and would appreciate your feedback regarding call '+ gr.number+' to the GSC.' +'<br />'+'<br />';

htmlContent += 'Number: '+ gr.number+'<br />';

htmlContent += 'Short Description: '+ gr.short_description + '<br />';

htmlContent += 'Opened Date/Time: '+ gr.sys_created_on + '<br />';

htmlContent += 'Resolved Date/Time: '+ gr.resolved_at + '<br />';

htmlContent += 'Closed Date/Time: '+ gr.closed_at + '<br />'+'<br />';

htmlContent += '</body>';

htmlContent += '</html>';

template.print(htmlContent);

3 REPLIES 3

shloke04
Kilo Patron

Hi,



Write an Notification script with the below line of code and call the same notification script in your Notification:



(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


/* Optional GlideRecord */ event) {



var url = 'https://' + gs.getProperty('instance_name') + '.service-now.com/your Portal Suffix?sys_id=' + current.sys_id + '&id=Mention your Id(if any)&table=Give your Table Name&view=sp';


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




})(current, template, email, email_action, event);



Hope this helps.Mark the answer as correct/helpful based on impact.




Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Thanks Shloke,



I created a new Email Script & called for it in the Notification Email.



This seems to print the Survey Instance # instead of the Incident #.   Any suggestions?



Thanks



(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


/* Optional GlideRecord */ event) {



var url = 'https://' + gs.getProperty('instance_name') + '.service-now.com/sp?sys_id=' + current.sys_id + '&id=ticket&table=incident&view=sp';


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



})(current, template, email, email_action, event);


I was able to do the below & get the link in Email Notification & works.




Just need to be able to print the Incident # & have this link hyperlinked




htmlContent += 'Link to Incident: https://xxx.service-now.com/sp?id=ticket&table=incident&sys_id='+ gr.sys_id + '<br />'+'<br />';




var htmlContent = '';


htmlContent += '<html>';


htmlContent += '<head>';


var gr = new GlideRecord('incident');


gr.get(current.trigger_id);


htmlContent += 'We are always looking to improve our service and would appreciate your feedback regarding call '+ gr.number+' to the SP.' +'<br />'+'<br />';


htmlContent += 'Number: '+ gr.number+'<br />';


htmlContent += 'Short Description: '+ gr.short_description + '<br />';


htmlContent += 'Opened Date/Time: '+ gr.sys_created_on + '<br />';


htmlContent += 'Resolved Date/Time: '+ gr.resolved_at + '<br />';


htmlContent += 'Closed Date/Time: '+ gr.closed_at + '<br />'+'<br />';


htmlContent += 'Link to Incident: https://xxx.service-now.com/sp?id=ticket&table=incident&sys_id='+ gr.sys_id + '<br />'+'<br />';


htmlContent += '</body>';


htmlContent += '</html>';


template.print(htmlContent);