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

Yes, I just want to remove the owner approvals, in the workflow, they are calling this scriptinclude for approvals. 

Original:

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;

 

 

 

Modified :

 

Remove logic related to owners

 

 

So last lines should be like 

  var kbManagers = knowledgeGR.kb_knowledge_base.kb_managers;

 return this._filterInactiveUsers(kbManagers);

        

 

Also check your other post where I explained the same.

Mark as accepted as solution and helpful it is resolved 

 

 

https://www.servicenow.com/community/developer-forum/modifying-ootb-script-include/m-p/3045740#M1145...