Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to add kb article in notification?

Servicenow10
Kilo Guru

hi 

i have 1 notification on incident table where i have to provide a link to kb article everytime this notification triggers.

so i wrote a email script and below is the code, but i only get the sys_id through it i want to print the content so how can i modify it to get results.

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

// Add your code here

var link = new GlideRecord("kb_knowledge");
link.addQuery("number", "KB0010002");
link.addQuery("sys_id","add9a529dbd7b344123655784a96199e");

template.print("<b>Article is</b>: <a href='" + gs.getProperty('glide.servlet.uri') + "kb_view.do?sys_kb_id=" + link.sys_id + "'>" + link.number + "</a><br/>");

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

 

am getting the link in my notification email script but when i click it gives record not found also it shows:

Article is : undefined

 

thanks

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi,

you did not use link.query() and link.next() in your mail script because of which link.number is coming as undefined

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP

View solution in original post

6 REPLIES 6

Bhagyashri Sor2
Tera Contributor

Hi,

Refer the following links

Email Notification - How to add link to KB Question or Article

KB Approval Notification

 

Make it correct and helpful.

Thanks

Bhagyashri Sorte

hi bhagyashree,

could you help me with this line as i am getting the error of unnecessary '\ escape character

template.print("<a href=\'" + instanceName + "nav_to.do?uri=kb_knowledge.do?sys_id=" + link.sys_id + "\'>" + link.number + "</a>");

Hi,

As you asked for the escape character issue. I think you are trying to use single quote and you won't close this before using double quote.

https://codegym.cc/groups/posts/escaping-characters-java

Servicenow10
Kilo Guru

find_real_file.pngi get this and when i click on undefined it takes me to correct page