Question about overriding the script include: KBKnowledgeSNC

jlaue
Kilo Sage

Hello - 

I am working on a requirement for the KB Article Expiry notification/configuration where currently if there are over 10 KBAs that need updated, it provides a URL to a list view of the articles.  I want to update this so that if it is over 30 it will do the same.

 

I found the script include that is driving this:  KBKnowledgeSNC   This is a read-only script and the script include: KBKnowledge is to be used for overriding, I am just not sure how to go about overriding it in that script.

 

KBKnowledgeSNC script include:

https://instancename.service-now.com/sys_script_include.do?sys_id=da5a4ab2d72121004792a1737e6103c5&s...

 

The function that is controlling this is on line 359 in the above script, "notifyForExpiringArticles".  I tried just copying all of that section of script from line 359 to 434 and pasting it into the 'KBKnowledge' script include override, however I am getting an error.

 

"Could not save record because of a compile error: JavaScript parse error at line (6) column (30) problem = missing } after property list (<refname>; line 6)"

 

This is what I have in the KBKnowledge script include:

https://instancename.service-now.com/nav_to.do?uri=%2Fsys_script_include.do%3Fsys_id%3D61308910eb022...

 

var KBKnowledge = Class.create();

KBKnowledge.prototype = Object.extendsObject(KBKnowledgeSNC, {

    type: "KBKnowledge"
    notifyForExpiringArticles: function() {
        if (gs.getProperty("glide.knowman.enable_article_expiry_notification", "false") === "true") {
            var userArticleMap = new function() {
                this._map = {};
                this.put = function(key, val) {
                    if (!this.containsKey(key)) {
                        this._map[key] = [];
                        this._map[key].push(val);
                    } else if (this._map[key].indexOf(val) == -1) {
                        this._map[key].push(val);
                    }
                };
                this.containsKey = function(key) {
                    return this._map.hasOwnProperty(key);
                };
                this.get = function(key) {
                    return this.containsKey(key) ? this._map[key] : null;
                };
                this.keys = function() {
                    var keys = [];
                    for (var key in this._map) {
                        if (this._map.hasOwnProperty(key)) {
                            keys.push(key);
                        }
                    }
                    return keys;
                };
            };

            var isVersioningEnabled = pm.isActive('com.snc.knowledge_advanced') && gs.getProperty("glide.knowman.versioning.enabled", "true") === "true";
            var gr = new GlideRecord('kb_knowledge');
            gr.addEncodedQuery('workflow_stateINpublished^kb_knowledge_base.active=true^valid_toONNext month@javascript&colon;gs.beginningOfNextMonth()@javascript&colon;gs.endOfNextMonth()');
            gr.orderBy('valid_to');
            gr.setCategory('homepage');
            gr.query();

            var isAOGEnabled = pm.isActive('com.snc.knowledge_advanced') && gr.isValidField("ownership_group") && gs.getProperty("glide.knowman.ownership_group.enabled", "true") === "true";
            while (gr.next()) {

                userArticleMap.put(gr.author + '', gr.getUniqueValue());

                if (isVersioningEnabled && gr.revised_by)
                    userArticleMap.put(gr.revised_by + '', gr.getUniqueValue());

                if (gr.kb_knowledge_base) {
                    userArticleMap.put(gr.kb_knowledge_base.owner, gr.getUniqueValue());
                    var kbManagers = gr.kb_knowledge_base.kb_managers;
                    if (kbManagers) {
                        var kbManagersList = kbManagers.split(',');
                        kbManagersList.map(function(kbmanager) {
                            userArticleMap.put(kbmanager + '', gr.getUniqueValue());
                        });
                    }
                }

                if (isAOGEnabled && gr.ownership_group) {
                    var aogMembers = new KBOwnershipGroup().getOwnershipGroupMembers(gr);
                    aogMembers.map(function(user) {
                        userArticleMap.put(user + '', gr.getUniqueValue());
                    });
                }
            }

            var maxArticleCount = 31;
            var users = userArticleMap.keys();
            var articleCount = 0;
            users.map(function(user) {
                var articleList = userArticleMap.get(user);
                articleCount = articleList.length;
                articleList = articleList.slice(0, maxArticleCount);
                var inputParam = {
                    articleList: articleList,
                    articleCount: articleCount,
                    isVersioningEnabled: isVersioningEnabled,
                    isAOGEnabled: isAOGEnabled
                };
                gs.eventQueue("kb.article.expiry.warning", null, user, JSON.stringify(inputParam)); //sending 31 articles displaying only 30 articles in email

            });
        }
    }

});
 
jlaue_0-1726508813737.png

 

Note - I only want to change the 'var maxArticleCount' variable so that it is 31 instead of 11.

 

Thanks!!

1 ACCEPTED SOLUTION

Voona Rohila
Kilo Patron
Kilo Patron

Also add a comma ( , ) after your function end (Line 86 and Line 87)

VoonaRohila_1-1726512138112.png

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

2 REPLIES 2

Voona Rohila
Kilo Patron
Kilo Patron

Hi @jlaue 

Line 5 in your code should be after all the functions

Example : 

VoonaRohila_0-1726511872300.png

 

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Voona Rohila
Kilo Patron
Kilo Patron

Also add a comma ( , ) after your function end (Line 86 and Line 87)

VoonaRohila_1-1726512138112.png

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP