
- 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 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 09:18 AM
This should work directly in the workflow correct?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2017 09:40 AM
The script I provided would go into KBWorkflow so it can override the KBWorkflowSNC class. If you do that, you actually shouldn't have to modify the workflow's approval activity at all, since it's calling the same script, but the script is now returning the KBWorkflow getApprovers method, instead of the KBWorkflowSNC getApprovers method.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2017 10:18 AM
GREAT! It's working for the most part. If there is a KB Owner and more than one manager OTHER than the Author, the list of approvers is the KB owner and all but ONE of the managers. No matter where I put the manager in the watch list or who else I add or remove from the list, that one doesn't show as an approver. I checked the roles for all users and they match. Where did you test this script, background script?