Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

knowledge articles should send OOTB expiry notification for 30 and 60 days servicenow

p_n
Tera Guru

OOTB notification works for 30 days. We tried to create a new email script to show content for articles eaxpiring in next 60 days. However the OOTB script include that triggers event considers authers/kb owners/kb manager etc, of articles expiring in 30 days. How to resolve this issue. All the authers/kb owners/kb managers should get the notification. We cannot update the script include as its read-only.

2 REPLIES 2

pratikjagtap
Giga Guru
Giga Guru

Hi @p_n ,

 

 

  • Clone the OOTB Script Include:

    • Create a new Script Include (e.g., CustomKBExpiryNotification).
    • Copy the logic from the OOTB Script Include.
    • Modify the condition to check for 60 days instead of 30.
  • Create a New Scheduled Job or Business Rule:

    • Trigger your custom Script Include for articles expiring in 60 days.
    • Ensure it fires the same event or a new custom event (e.g., kb.expiry.60days).
  • Create a New Notification:

    • Link it to your custom event.
    • Add recipients: authors, KB owners, KB managers.

If my response helped, please hit the 👍Thumb Icon and accept the solution so that it benefits future readers.

 

Regards,
Pratik

 

Chaitanya ILCR
Mega Patron

Hi @p_n ,

 

you can update the OOB scheduled job (Notification for Article Expiry Warning)

update as highlighted

changes changed it to run daily and commented few lines in the condition

ChaitanyaILCR_2-1761586803243.png

 

 

now go to the script include (KBKnowledge) this is for customers to override the OOB functionality of script include (KBKnowledgeSNC) which is readonly

and update it as this

ChaitanyaILCR_3-1761587352465.png

 

 

if you already have update the script include just append or update the method (notifyForExpiringArticles)

as below

var KBKnowledge = Class.create();

KBKnowledge.prototype = Object.extendsObject(KBKnowledgeSNC, {

    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_toRELATIVEGT@dayofweek@ahead@59^valid_toRELATIVELT@dayofweek@ahead@61");
            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 = 11;
            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 11 articles displaying only 10 articles in email

            });
        }
    },

    type: "KBKnowledge"
});

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya