Mail Script not working when we preview notification.

PriyanshuVerma1
Tera Expert

I have created a mail script for using it in kb article expiry notification which is as follows : 

 

 

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

    // Add your code here
    var obj = new KBKnowledge().getNotificationObject(current)
    var valid_to = obj.valid_to;
    //Convert the valid to date value to a javascript date object
    var valid_to_date = new Date(getDateFromFormat(valid_to, g_user_date_format));
    //Get the current date
    var today = new Date();
    //Compare the dates and get the difference in milliseconds
    var diff_ms = valid_to_date.getTime() - today.getTime();
    //Convert the difference to days
    var diff_days = Math.round(diff_ms / 86400000);
    var emailContent = {};
    emailContent.templateContent = 
        "Hi"+
    "<br/>" +
    "<a href="+obj.article_link+">"+obj.number+"</a> is about to expire in" + diff_days+
    "<br/>" +
    "<b>Article Title</b>: "+obj.short_desc+"<br/>" +
    "<br/>" +
    "Please review the article it is valid till" + obj.valid_to+ "."+
    "<br/>";    
    email.setSubject(obj.number+" is going to expire.");
    template.print(emailContent.templateContent);
   
    
    

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

 

But when i preview it, it looks all blank, I have used the similar approach of using object for calling knowledge article for approval notification and it works perfectly.

Can someone please guide me where I am wrong

4 REPLIES 4

karthiknagaramu
Kilo Sage

Hi,

 

In this line,

var valid_to_date = new Date(getDateFromFormat(valid_to, g_user_date_format));

you are using g_user_date_format. Is this available to use in the email script?

 

Regards,

Karthik Nagaramu

How can I check if it is available to use in email script. Although I believe the syntax is correct.

I believe this line code can be used only in client script and not in email script.

Please comment all the data manipulations and check if notification preview works.

Then the problem is in the date manipulation.

i noticed the issue is with table i am selecting in notification record. I removed all the code related to date manipulation and only have :

var obj = new KBKnowledge().getNotificationObject(current);

var emailContent = {};
    emailContent.templateContent = 
        "Hi"+
    "<br/>" +
    "<a href="+obj.article_link+">"+obj.number+"</a> is about to expire in" +
    "<br/>" +
    "<b>Article Title</b>: "+obj.short_desc+"<br/>" +
    "<br/>" +
    "Please review the article it is valid till" + obj.valid_to+ "."+
    "<br/>";    
    email.setSubject(obj.number+" is going to expire.");
    template.print(emailContent.templateContent);
   

When I am selecting approval table it is previewing some stuff, but not when I select knowledge table