- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2018 10:01 AM
Hi Every One ,
Brand new KB Article: Goes through KBApprove workflow.
Upon close of KBApprove, Employee Knowledge workflow starts.
User clicks UI Button to "Republish":
Cancel the Employee Knowledge workflow and start the KBApprove workflow.
Upon close of KBApprove workflow, a new Employee Knowledge workflow starts.
Issue : when i click on "Republish button" it is creating new KbApprove workflow, when KB APProve is Activated then earlier created Employee KB workflow is to be deleted in Workflow Context , but it is still running, i just want to delete that Second workflow-Employee KB from workflow Context. and Once i Published KB record then KBAprove is finished that time only Employee KB Should come to Active state.
Employee Knowledge -workflow
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2018 08:13 PM
Ok. Great. So this should work all fine. This should be at the beginning of the KB Approval workflow
var wf =new GlideAggregate('wf_context');
wf.addEncodedQuery('workflow_versionLIKEKB approval V2^active=false^id='+current.sys_id);
wf.addAggregate('COUNT');
wf.query();
var wcounts =0;
var deletecount = 0;
if(wf.next())
wcounts = wf.getAggregate('COUNT');
var inc= new GlideRecord('wf_context');
inc.addEncodedQuery('workflow_versionLIKEKB approval V2^active=false^id='+current.sys_id);
inc.orderBy('sys_created_on');
inc.query();
while(inc.next())
{
deletecount = deletecount++;
if (deletecount<wcounts)
inc.deleteRecord();
}
GlideRecord('wf_context');
inc.addEncodedQuery('workflow_versionLIKEEmployee Knowledge^id='+current.sys_id);
inc.orderBy('sys_created_on');
inc.query();
while(inc.next())
{
inc.deleteRecord();
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2018 08:07 AM
Hi Sanjiv,
Can i expect any updates please

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2018 07:07 PM
Sorry I am travelling. Try this. You need both the scripts
Use this
var wf =new GlideAggregate('wf_context');
wf.addEncodedQuery('workflow_versionLIKEKB approval V2^active=false^id='+current.sys_id);
wf.addAggregate('COUNT');
wf.query();
var wcounts =0;
var deletecount = 0;
if(wf.next())
wcounts = wf.getAggregate('COUNT');
var inc= new GlideRecord('wf_context');
inc.addEncodedQuery('workflow_versionLIKEKB approval V2^active=false^id='+current.sys_id);
inc.orderBy('sys_created_on');
inc.query();
while(inc.next())
{
deletecount = deletecount++;
if (deletecount<wcounts)
inc.deleteRecord();
}
GlideRecord('wf_context');
inc.addEncodedQuery('workflow_versionLIKEEmployee Knowledge^id='+current.sys_id);
inc.orderBy('sys_created_on');
inc.query();
while(inc.next())
{
inc.deleteRecord();
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2018 02:00 AM
Hi Sanjeev,
I have one query here,
With little confusion,
When we click on "REPUBLISH" then only "employee Kb" workflow should be deleted, KBapprove workflow should active.
We are running above script in workflow Runscript--when we click on "REPUBLISH" button then "KBApprover" workflow activated , in that workflow we whave Runscript it will be activated when Kbapprove workflow is going to end.so what happens if we have any privously closed kbapprove records in workflow context that records will be deleted recently closed kbapprove record available r...right.
If we see when KBApprove ended EmployeeKb should be activated...as per the script it is deleted.
OurThread is: if new KBAPPROVER workflow activated that time only it will be deleted....when kbapprover is ended, EmployeeKb active....

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2018 03:00 AM
Hi Chanikya,
In KB Approver workflow, the script i provided should be the first activity after begin. This will delete at old KB Approver workflows and the Employee Knowledge. Once the KB Approver workflow ends, I think you would be setting the approval state to approved. the New Employee Knowledge workflow should begin again based on the condition state=approved set in the Employee Knowledge workflow.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2018 03:51 AM