modifying ootb script include

Snow-Man
Tera Contributor

Hello guys, 

 

There is an OOTB script include with getapprovers function.

Screenshot 2024-09-16 at 11.09.47 AM.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.
 
How can I modify and extend this?  

 

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;

 

 

thanks in advance,

snowman

2 ACCEPTED SOLUTIONS

Mani A
Tera Guru

getApprovers: function(knowledgeGR) {

    if (this.isVersioningInstalled() && gs.getProperty("glide.knowman.ownership_group.enabled", 'false') === 'true') {

        var users = new KBOwnershipGr

        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); // Remove author from the list if self-approval is not allowed

            }

        }

        

        if (users.length > 0) {

            users = this._filterInactiveUsers(users.toString()); // Filter out inactive users

            if (!gs.nil(users)) {

                return users; // Return the filtered list of ownership group members

            }

        }

    }

    var kbManagers = knowledgeGR.kb_knowledge_base.kb_managers;

    return this._filterInactiveUsers(kbManagers); 

}

 

View solution in original post

@Snow-Man  check my above code..it will work for your case. Only last 2lines are enough and remaining should be removed from original script..for kbowner

Also override OOB script include to customize the logic

 

To override the initialize function in an OOTB script include, you can follow these steps:

 

Create a new script include that extends the OOTB script include.

In the new script include, define a function with the same name as the initialize function in the OOTB script include.

In the new function, add your custom code.

When you are finished, save the new script include.

When you use the new script include, your custom code will be executed instead of the initialize function in the OOTB script include.

 

Mark it as accepted as solution and helpful if it resolved

View solution in original post

10 REPLIES 10

Mani A
Tera Guru

getApprovers: function(knowledgeGR) {

    if (this.isVersioningInstalled() && gs.getProperty("glide.knowman.ownership_group.enabled", 'false') === 'true') {

        var users = new KBOwnershipGr

        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); // Remove author from the list if self-approval is not allowed

            }

        }

        

        if (users.length > 0) {

            users = this._filterInactiveUsers(users.toString()); // Filter out inactive users

            if (!gs.nil(users)) {

                return users; // Return the filtered list of ownership group members

            }

        }

    }

    var kbManagers = knowledgeGR.kb_knowledge_base.kb_managers;

    return this._filterInactiveUsers(kbManagers); 

}

 

@Snow-Man  check my above code..it will work for your case. Only last 2lines are enough and remaining should be removed from original script..for kbowner

Also override OOB script include to customize the logic

 

To override the initialize function in an OOTB script include, you can follow these steps:

 

Create a new script include that extends the OOTB script include.

In the new script include, define a function with the same name as the initialize function in the OOTB script include.

In the new function, add your custom code.

When you are finished, save the new script include.

When you use the new script include, your custom code will be executed instead of the initialize function in the OOTB script include.

 

Mark it as accepted as solution and helpful if it resolved

Snow-Man
Tera Contributor

Thank you Mani 🙂

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Snow-Man 

To summarize, you want to

--> Send approval only to the ownership group.

--> If the ownership group is empty or null, send approval to knowledge base managers

--> Remove the part of the script that sends approval to KB owners.

Below code will work :-

getApprovers: function(knowledgeGR) {
if (this.isVersioningInstalled() && gs.getProperty("glide.knowman.ownership_group.enabled", 'false') == 'true') {
var users = new KBOwnershipGroup().getOwnershipGroupMembers(knowledgeGR);
if (users.length > 0) {
users = this._filterInactiveUsers(users.toString());
if (!gs.nil(users)) {
return users;
}
}
}
// If ownership group is empty or null, send approval to knowledge base managers
var kbManagers = knowledgeGR.kb_knowledge_base.kb_managers;
return this._filterInactiveUsers(kbManagers);
}

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/