Add KB Article link in notification

Priya75
Tera Contributor

Hi All,

I want to fetch the Kb article number from incident ,So there is a filed on incident form as  u_knowledge which saves trhe kb article number. i want to give the link of that particular KB article in portal view from the notification.

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Priya,

you need to use mail script for this

Name: show_kb_link

Include it in notification like this

${mail_script:show_kb_link}

Script:

Note: Ensure you use valid query based on whether u_knowledge is reference type or string type

(function runMailScript(current, template, email, email_action, event) {

	var KbNumber = current.u_knowledge;
    var kbRecord = new GlideRecord('kb_knowledge');
    kbRecord.addQuery('number', KbNumber); // if KbNumber stores number
	
	// OR
	
	kbRecord.addQuery('sys_id', KbNumber); // if KbNumber stores sys_id
	
    kbRecord.query();
    if(kbRecord.next()) {
	// this would take user to portal
    var url = '/sp?id=kb_article&sys_id=' + kbRecord.sys_id + 'table=kb_knowledge';
    template.print('<a href="' + url + '">' + kbRecord.number + '</a>');
	}
	
})(current, template, email, email_action, event);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

it is not working.i am not getting any link in the notification

Hi Priya,

u_knowledge is reference to kb_knowledge or string which stores KB number

you need to use proper query accordingly

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

 yes i have used the sys_id one, it redirect one but it takes me to the portal but knowledge article record is not displayed .

Hi Priya,

so to which page it is taking?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader