extending an OOB script include

Snow-Man
Tera Contributor

Hello guys, 

 

There is an OOTB script include with getapprovers function.

SnowMan_0-1726508173720.png

 

Inside this function, we have the following code, my requirement is to make changes to this code and send approval only to ownership group and if ownership group is empty or null, approval should be sent to knowledge base managers. we need to remove the part of the script which sends approval to Kb owners. I don't need that.
 

 

getApprovers: function(knowledgeGR) {
        if (this.isVersioningInstalled() && gs.getProperty("glide.knowman.ownership_group.enabled",'false') +'' == 'true') {
            var users = new KBOwnershipGroup().getOwnershipGroupMembers(knowledgeGR);
            if (gs.getProperty("glide.knowman.ownership_group.allow_self_approval", 'true') == 'false') {
                var author = (knowledgeGR.revised_by && knowledgeGR.revised_by != '') ? knowledgeGR.getValue("revised_by") : knowledgeGR.getValue("author");
                if (users.indexOf(author) != -1)
                    users.splice(users.indexOf(author), 1);
            }
            if (users.length > 0) {
                users = this._filterInactiveUsers(users.toString());
                if (!gs.nil(users))
                    return users;
            }
        }
        var kbOwner = knowledgeGR.kb_knowledge_base.owner;
        var kbManagers = knowledgeGR.kb_knowledge_base.kb_managers;
        var approvers = '';
        if (kbOwner.active) {
            //Approval activity will handle any trailing comma, if there are no managers.
            approvers = kbOwner + ",";
        }
        approvers = approvers + this._filterInactiveUsers(kbManagers);
        return approvers;
    },
    /*
     * Internal function used to fetch invalid users and remove them from user list.
     *
     * @Param users- comma seperated list of user_ids
     * @return String-comma seperated list of user_ids
     */
    _filterInactiveUsers: function(users) {
        if (gs.nil(users)) {
            return '';
        }
        //Fetch for inactive users.
        var inactiveUsers = new GlideRecord('sys_user');
        inactiveUsers.addQuery("active", "false");
        inactiveUsers.addQuery('sys_id', 'IN', users);
        inactiveUsers.query();
		//Check for any inactiveusers.
        if (inactiveUsers.hasNext()) {
            var userArray = users.split(",");
            while (inactiveUsers.next()) {
                var useridx = userArray.indexOf(inactiveUsers.getUniqueValue()+'');
                if (useridx != -1)
                    userArray.splice(useridx, 1);
            }
            users = userArray.toString();
        }
        return users;
    },

 

This is already an ootb script include to Override out-of-the-box calls for KBWorkflowSNC.
how can I add the code in it? 
also since get approvers function is using filteractiverusers so how can I add that too in another script include?
 
thanks in advance 

 

6 REPLIES 6

Voona Rohila
Kilo Patron
Kilo Patron

Hi @Snow-Man 

To add your custom logic or to override any method, you can use KBWorkflow Script include( Which is provided to Override out-of-the-box calls for KBWorkflowSNC)

VoonaRohila_0-1726513375813.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

Hi, I tried doing it but it is not working, any help? 

 

Bert_c1
Kilo Patron

copy the function you want to change from the  KBWorkflowSNC script include to the  KBWorkflow script include, and make your change there. As recommend by Voona.

Ravi Peddineni
Kilo Sage

@Snow-Man 

 

What is your use case here? And why do you want to extend the OOTB script Include? If this is just to remove owner approvals, You can just edit the workflow or create a new one and use it in the KBs