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

Thanks for the code, how do we extend/override an ootb script include? 

Hi @Snow-Man 

below thread will work :-

https://www.servicenow.com/community/developer-forum/how-to-override-initialize-function-in-ootb-scr...

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


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/

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Snow-Man 

 

Look like you are interested in one person answer and its a game which everyone know why you are accepting the answer from a single individual. Like this you can't reach Heights.

All the Best will ask Servicenow moderator team to check on this

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


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/

Hi Ravi,

First of all, I don’t need to explain myself to you, but I still can, because your help has been invaluable. 

Excuse me for accepting Mani's solution and not yours. Mani's was way more detailed (step by step of how to achieve it). Since, I am new to it, I needed a detailed version.

 

Also, I didn't find your link to extend script include much useful. 

So, I chose Mani over yours. 

 

Ps. I follow you on YT :), I wouldn't not have done that if I was the one you think I am 🙂

Hi @Snow-Man 

Understood.. maybe its my mistake as I have seen lot of Spam like this.. I am sorry If you feel bad about it.

And Thanks you cleared my POV.

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


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/