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

Jaspal Singh
Mega Patron
Mega Patron

Hi Priya,

 

You can do below.

1. Create mail script - getkblink

2. Code as below.

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

    // Add your code here
	var kbis=current.u_knowledge;
    var getarticle = new GlideRecord('kb_knowledge');
    getarticle.addQuery('sys_id',kbis);
    getarticle.query();
    while (getarticle.next()) {
    var urlis = '/sp?id=kb_article&sys_id=' + getarticle.sys_id + 'table=kb_knowledge';
    template.print('<a href="' + urlis + '">' + gs.getMessage(getarticle.number) + '</a>');
	}
})(current, template, email, email_action, event);

3. Call the mail script in Incident notifications body in format ${mail_script:getkblink}

asifnoor
Kilo Patron

Hello Priya

you need a email script for this. Assuming notification is on incident table, create a mail script and call in the notification

${mail_script:get_kbarticle_link}

Mail script: get_kbarticle_link

script

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
         var attachLink = '<a href="' + gs.generateURL('kb_knowledge',current.u_knowledge) +  '">' + current.u_knowledge.getDisplayValue()+ '</a>';
         template.print(attachLink +  "<br />");
})(current, template, email, email_action, event);

Mark the comment as a correct answer and also helpful once worked.

 

Hello Priya,

Did you check the code that i have given. If want the link to open in a portal, just use the below code and it will work.

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
         
          var attachLink = '<a href="' + gs.getProperty('glide.servlet.uri')+'/sp?id=kb_article&sys_id='+current.u_knowledge +  '">' + current.u_knowledge.getDisplayValue()+ '</a>';
         template.print(attachLink +  "<br />");
})(current, template, email, email_action, event);

Mark the comment as a correct answer and also helpful once worked.

Hello Priya,

kindly mark the comment as a correct answer if this code has worked for you.