Need help in understanding the OOTB script

bhargavi9
Tera Contributor

Hi All,

We are working on a requirement where we need to modify the OOTB script. We need to comment out two lines that are restricting our script. Can anyone help us understand the script?  Thanks.


Below are the two lines that need to be commented.

1.if(!this.canNotify(knowledge_gr.author,current))
2.continue;

Function that is calling

canNotify: function(user,current) {
        var live_profile = this.getLiveProfileId(user);
        //check for users notification preference for the stream
        var userStream = new ActivitySubscriptionContext().getSubscriptionService().getUserStream(live_profile, 'Notification', true);
        if(userStream && userStream.name == 'Notification' && !userStream.fanout_to_stream)
            return false;

        if(new ActivitySubscriptionContext().getSubscriptionService().isSubscribed(current.object_id.sys_id,live_profile).subscriptionId) {
            var pref = new ActivitySubscriptionContext().getSubscriptionService().getPreferences(live_profile,'7d8f537453003200fa9bd7b08cc5872c');
            return this.checkPrefCode(pref.preferences.activities,current);
        }
        return false;
    },
1 REPLY 1

Robbie
Kilo Patron
Kilo Patron

Hi @bhargavi9,

 

The method you refer to is part of the Script Include ('class'): KBFanoutManagerSNC.

ServiceNow have provided a 'subclass' and Script Include for you to override this method as you require. The subclass and Script Include you require is: KBFanoutManager

 

Within this Script Include ('KBFanoutManager') you can update as you require without affecting the parent and base class.

 

The syntax would be as below.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.




Thanks, Robbie

 

//Template
// functionNameYouWantToOverride: function() {
//	... 
// },

//For your specific requirement:
var KBFanoutManager = Class.create();
KBFanoutManager.prototype = Object.extendsObject(KBFanoutManagerSNC, {

notifyAuthorReviser: function(obj,event_name,current) {

		if(obj.class_name == 'kb_knowledge_block') return;
		var author_reviser = [];
		var knowledge_gr = new GlideRecord('kb_knowledge');
		knowledge_gr.addActiveQuery();
		knowledge_gr.setWorkflow(false);
		if(current.object_id.article_id.nil())
			knowledge_gr.addQuery('sys_id',current.object_id.sys_id);
		else
			knowledge_gr.addQuery('article_id',current.object_id.article_id);

		knowledge_gr.query();
		while(knowledge_gr.next()) {
			if(knowledge_gr.revised_by && knowledge_gr.revised_by != current.actor_id && new ArrayUtil().indexOf(author_reviser,knowledge_gr.revised_by) == -1 ) {
				//if(!this.canNotify(knowledge_gr.revised_by,current))
					//continue;
				obj.receiver = knowledge_gr.revised_by.first_name+'';
				gs.eventQueue(event_name,current,knowledge_gr.revised_by,new JSON().encode(obj));
				author_reviser.push(knowledge_gr.revised_by+'');	
			}
			else if(!knowledge_gr.revised_by && knowledge_gr.author != current.actor_id && new ArrayUtil().indexOf(author_reviser,knowledge_gr.author) == -1) {
				//if(!this.canNotify(knowledge_gr.author,current))
					//continue;
				obj.receiver = knowledge_gr.author.first_name+'';
				gs.eventQueue(event_name,current,knowledge_gr.author,new JSON().encode(obj));
				author_reviser.push(knowledge_gr.author+'');
			}
		}
	},
type: 'KBFanoutManager'
});