- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 10:46 PM
Hello guys,
There is an OOTB script include with getapprovers function.
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 10:52 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 11:37 PM - edited 09-15-2024 11:53 PM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 10:52 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 11:37 PM - edited 09-15-2024 11:53 PM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 08:48 PM
Thank you Mani 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 11:30 PM
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/