How to conditionally add a button to email notification

breharabalya
Tera Contributor

I'm trying to create a button in an email notification that links to the SLA ticket. I currently have an email script for a "button bar" that contains buttons linking to the ticket, SN and a KB article. Just trying to only add an SLA ticket link button when the email notification is for an SLA breach or warning.

2 REPLIES 2

Vismit Ambre
Giga Guru

You can have the condition in your notification email script and perform a template.print based on if the condition has been satisfied or not.

 

For example:

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var emailBody = '<button>Go to ticket</button>';
    if (event.parm1 == 'Closed') {
        emailBody += '<button href = https://www.' + gs.getProperty('instance_name') + '.service-now.com/>Go to SLA Ticket</button>';
    }

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

Please mark the solution accepted or helpful so that it can be referred in case anyone else has similar question in future.

 

Regards,

Vismit

ersureshbe
Giga Sage
Giga Sage

Hi, I recommend using the change ticket approval notification template as a reference. Use the same logic for your requirements. 

Regards,
Suresh.