
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2017 08:26 AM
Team...
I'm looking for a lightweight solution to prohibit the author of an article from approving their own article. I have added the 'Approvers' related list to the Knowledge v.3 form and know that I can change the query for it to leave the author out, but the approval request still shows in Self Service > My Approvals. In the work flow for the OOB Knowledge - Approval Publish, at the approval step it calls the KBWorkflow().getApprovers(current); which extends the KBWorkflowSNC().getApprovers(current); script include:
getApprovers: function(knowledgeGR) {
var kbOwner = knowledgeGR.kb_knowledge_base.owner;
var kbManagers = knowledgeGR.kb_knowledge_base.kb_managers;
//Approval activity will handle any trailing comma, if there are no managers.
return kbOwner + "," + kbManagers;
If the author is a manager or happens to be the KB owner, I don't wnat them to be a possible approver of the article. Thank you in advance for your help!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2017 09:12 AM
Mike,
What you should do is push all the people who could possibly be approvers into an array, then filter the array to not include the KB author. You'll need to account for what happens if there is only one possible approver and that person is the author. Maybe have a backup person or allow them to approve their own article in that case?
I didn't test this exact script in a workflow but I did test the filtering logic and it seems to do what you are asking about.
getApprovers: function (knowledgeGR){
var kbOwner = knowledgeGR.kb_knowledge_base.owner;
var kbManagers = knowledgeGR.kb_knowledge_base.kb_managers;
var approvers = [];
approvers.push(kbOwner);
if (kbManagers){
var managersArray = kbManagers.split(','); //kb_managers is a GlideList field, which is a comma-separated set of sys_ids. Split to them so you can work with it as an array
approvers = approvers.concat(managersArray);
}
/*Optional: only filter the approvers if there is more than one person. That way, your users can approve their own articles if nobody else is available.
if (approvers.length > 1){
var filteredApprovers = approvers.filter(filterOutAuthor);
return filteredApprovers;
} else {
return approvers;
}
*/
//Always filter out the author from the approvers list.
var filteredApprovers = approvers.filter(filterOutAuthor);
return filteredApprovers;
function filterOutAuthor(sysid){
return knowledgeGR.author != sysid;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2017 11:42 AM
I tested this in Fix Scripts (so you can save it and use the script editor). Definitely works for me.
Save this as a fix script and test it against the KB article you are experimenting with. You would expect it to log all the owners plus the manager, minus the author of the KB article. Make sure you carefully read the logs to see who the author is, and if they are a manager. It works correctly for me.
(function testFilter(){
var knowledgeGR = new GlideRecord('kb_knowledge');
knowledgeGR.get('593d74ab6ffc3280543f4035eb3ee4ed'); //Replace to test with a different article.
gs.info('Author: ' + knowledgeGR.getValue('author'));
var approvers = [];
var kbOwner = knowledgeGR.kb_knowledge_base.owner;
var kbManagers = knowledgeGR.kb_knowledge_base.kb_managers;
gs.info('Owner: ' + kbOwner);
gs.info('Managers: ' + kbManagers);
//KB owner is alwyas an approver.
approvers.push(kbOwner);
//If there are managers, they are approvers, too. Checking for managers before splitting prevents that situation where you split a null.
if (kbManagers){
//kb_managers is a GlideList field, which is a comma-separated set of sys_ids. Split to them so you can work with it as an array
approvers = approvers.concat(kbManagers.split(','));
gs.info('added these managers as approvers: ' + approvers);
}
var filteredApprovers = approvers.filter(filterOutAuthor);
gs.info('Filtered approvers: ' + filteredApprovers);
function filterOutAuthor(sysid){
return knowledgeGR.author != sysid;
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 09:52 AM
Partick,
Thank you for your help on this! I went a step further and ran the approvals array through the arrayUtil.unique to make sure there were no duplicates. This is working very well.