Notifications email script

Rob Sestito
Mega Sage

Hello SN Comm,

I am looking for a little help with a notification email script.

Specifically, both the KM Subscription: Article Commented and the KM Subscription Group: Article Commented.

Currently, too many employees are being notified on when an article receives a comment from the portal.

Even someone that has nothing to do with the article being commented on. I am trying to figure out how that is even possible and looking for help. I think it is coming from the email script itself, but not 100%.

Here is what we have:

KM Subscription: Article commented

When to send: Event is fired --> Event name: sn_actsub.notify_about_article_commented --> Who will receive: Event parm1 contains recipient --> What will it contain: ${mail_script:Notification: Article commented}

Here is the script for the mail_script:Notifications:Article Commented

(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.article_id);
	var emailContent = {};
	emailContent.templateContent = 

    "Hi  "+obj.receiver+",<br/>" + 
	"<br/>" +
	"An article that you have created/updated has received a new comment.<br/>" + 
	"<br/>" + 
	"<b>Article Number</b>: <a href='"+article_link+ "'>"+obj.article_number+"</a><br/>" +
	"<b>Article Title</b>: "+obj.short_desc+"<br/>" +
	"<b>Commented By</b>: "+obj.commented_by+"<br/>" +
	"<b>Received On</b>: "+obj.commented_on+"<br/>" +
	"<b>Comment</b>: "+obj.comment+"<br/>" +
	"<br/>" +
	"If this comment requires you to update the article, you may do so from " +
	"<a href='"+gs.getProperty('glide.servlet.uri')+"kb_knowledge.do?sys_id="+	obj.latest_version_id +"'>here.</a><br/>";
	
	var vars={
		url: gs.getProperty('glide.servlet.uri'),
		articleobj : obj
		};
    var extensionPoint = new GlideUIExtensionPoint().getExtensions("global.KMFeedbackNotification", vars);
    if(extensionPoint.length > 0){
       emailContent.templateContent = extensionPoint[0];
     }
	email.setSubject(obj.subject);
	template.print(emailContent.templateContent);
	

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

A total of four people receive the email when an article is commented on.

When I look at the history of the article, the group owner and the author, or anyone that has updated anything on said article, two of the four have nothing to do with it. And I am not able to catch why they are getting the notifications.

Anyone able to lend a hand? Much appreciated!

-Rob

1 ACCEPTED SOLUTION

Tony Chatfield1
Kilo Patron

Hi, the script in your post populates email body\content and I don't see any indication that it populates recipients. your script would need to populate a recipient like this

//email.addAddress(type, address, displayname);

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/script/server-scripting/reference/r_ExScptEmlNtfn.html

Based on your description eventParm1 is the source of the recipients.
When you check the sysevents in the event log, do all of the recipients appear in parm1 field? if yes then they are bing passed in by the code that generates the sysevent.

This article explains why users may get unexpected notifications for sn_actsub.notify_about_article_revise_kb
And I would check in case the underpinning cause is the same, IE users get the notifications as they are subscribed to the articles.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0787204

 

View solution in original post

3 REPLIES 3

Tony Chatfield1
Kilo Patron

Hi, the script in your post populates email body\content and I don't see any indication that it populates recipients. your script would need to populate a recipient like this

//email.addAddress(type, address, displayname);

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/script/server-scripting/reference/r_ExScptEmlNtfn.html

Based on your description eventParm1 is the source of the recipients.
When you check the sysevents in the event log, do all of the recipients appear in parm1 field? if yes then they are bing passed in by the code that generates the sysevent.

This article explains why users may get unexpected notifications for sn_actsub.notify_about_article_revise_kb
And I would check in case the underpinning cause is the same, IE users get the notifications as they are subscribed to the articles.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0787204

 

Hey Tony,

Thanks for replying on this.

When I check into the sysevents, I am seeing that the users are being captured in parm2.

The Notification Email Script on this does have parm2 scripted within it.

The Email Notification being fired by the Event has parm1 checked.

But each user from the sysevents are showing within the parm2 field.

Here is an example of one - I highlighted my comment and the person as a receiver, which is the part we do not understand why.

find_real_file.png

 

I think the issue may actually be when was said in the article you sent me.

"The reason for sending out notifications to users no related to the article is that because notifications are also sent to the people who are subscribed to the knowledge base."

 

Hey Tony,

That led me in the right direction and I was able to see where users are subscribed to bases and then articles.

I was able to see the users being subscribed to a lot - hence they are getting these notifications.

Thank you sir!

-Rob