We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Short description as hyperlink in email notification

ceraulo
Mega Guru

Hello!

 

I have a requirement to create an email notification where the email body contains the short description of the ticket. This short description will be a hyperlink to the ticket. Is this possible?

I am unable to use {URI_REF} because the the display shows the ticket number instead of the short description.

Please help! 

1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

Hi @ceraulo,

 

You need to construct the URL and add it to the notification using anchor tags in email scripts as follows:

    var url = '<a href="' + gs.getProperty('glide.servlet.uri') + current.getTableName() + '.do?sys_id=' + current.getUniqueValue() + '">' + current.short_description + '</a>';
    template.print(url + "<br />");

 

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow

View solution in original post

3 REPLIES 3

Sagar Pagar
Tera Patron

Hi @ceraulo,

 

You need to construct the URL and add it to the notification using anchor tags in email scripts as follows:

    var url = '<a href="' + gs.getProperty('glide.servlet.uri') + current.getTableName() + '.do?sys_id=' + current.getUniqueValue() + '">' + current.short_description + '</a>';
    template.print(url + "<br />");

 

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow

Riya Verma
Kilo Sage

Hi @ceraulo ,

 

Hope you are doing great.

 

Create an email notification script to include the ticket's short description as a hyperlink:

 

// Step 1: Create a new email notification script
// This script fetches the short description and ticket number and includes it as a hyperlink in the email body

var shortDescription = current.short_description;
var ticketNumber = current.number;
var ticketLink = gs.getProperty('glide.servlet.uri') + current.getLink(true);

// Define the email body
var emailBody = "Hello,\n\n";
emailBody += "You have a new ticket: <a href='" + ticketLink + "'>" + shortDescription + "</a> (Ticket Number: " + ticketNumber + ").\n";
emailBody += "Please review the ticket for further action.\n\n";
emailBody += "Best regards,\nYour IT Team";

// Set the email body
email.setBody(emailBody);

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Arun_S1
Tera Guru

@ceraulo Create a new email script "short_description_link" with the following script

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

    // Add your code here
    var tbl = current.getTableName();
    var sysID = current.sys_id;
    var link = createLinkForObject(tbl, sysID, current.short_description);
    template.print(link);

    function createLinkForObject(strTableName, strSysID, short_description) {
        return '<a href="' + gs.getProperty('glide.servlet.uri') + gs.generateURL(strTableName, strSysID) + '">'+short_description+'</a>';
    }

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

 

2. In the email notification replace ${URI_REF} with ${mail_script:short_description_link}

 

Please mark the appropriate response as correct answer and helpful.

Thanks!!