add KB article body text in "Notification: Article created "

varunp
Tera Guru

We want all users who subscribed to the knowledge base will get the email if new article is created.

This feature is OOB and working fine.

But when I try to add the article's body in the email, it is giving undefined.

 

 

 

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

var obj = new JSON().decode(event.parm2);
var article_link = new KBCommon().getArticleLink(obj.sys_id);
email.setSubject("Reg: A new article "+obj.number+" has been created in "+obj.knowledge_base+" Knowledge Base.");
template.print("Hi "+obj.receiver+",<br/>");
template.print("<br/>");
template.print("An article has been created in the "+obj.knowledge_base+" Knowledge Base.<br/>");
template.print("<br/>");
template.print("<b>Article Number</b>: <a href='"+article_link+ "'>"+obj.number+"</a><br/>");
template.print("<b>Published Date</b>: "+obj.created_on+"<br/>");
template.print("<b>Body</b>: "+ obj.text+"<br/>");

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

 

find_real_file.png

4 REPLIES 4

Lansford Hazel
Giga Expert

Hi,

What table is the notification running on? Why are you not using current?

If the notification is running on the knowledge table you would be able to access it by using current.text

find_real_file.png

 

 

Its running on "Activity" table

I can see you already have the KB article sys_id so all you need to do is the following:

// Get the knowledge record from the data base
var knowledgeGr = new GlideRecord('kb_knowledge')
knowledgeGr.get(obj.sys_id);

template.print(knowledgeGr.getValue('text'))

 

Eric Viets
Mega Expert

Check out another post similar to yours that I replied to and was identified as the correct answer:

https://community.servicenow.com/community?id=community_question&sys_id=1d37112adb88ab04e0e80b55ca96...