- 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-27-2018 10:20 AM
You can write a script in the kbapprove workflow. Query the workflow context by it's name and delete it. Query on wf_context table
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-27-2018 11:12 AM
Hi,
Using with this script i can able to delete KBApprove workflow if it is more than one KBApprove record in Workflow Context.
Now i want to delete Employee KB workflow from workflow context when KBApprove is activated.
"
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.
"
Can i use this :Query line.- workflow_versionLIKEEmployee Knowledge -Retied^state=executing^active=true
Script:
var wf =new GlideAggregate('wf_context');
wf.addEncodedQuery('workflow_versionLIKEKB approval V2^active=false');
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');
inc.orderBy('sys_created_on');
inc.query();
while(inc.next())
{
deletecount = deletecount++;
if (deletecount<wcounts)
inc.deleteRecord();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2018 04:33 AM
Try this. Use the document_id part in the kbapproval v2 approval script as well which I missed last time.
GlideRecord('wf_context');
inc.addEncodedQuery('workflow_versionLIKEEmployee Knowledge^document_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 04:51 AM
Hi Sanjiv,
i have tried with script in different ways also , but not working
Could you please help me on this.
First time i have with this script : No result
var wf =new GlideAggregate('wf_context');
wf.addEncodedQuery('workflow_versionLIKEKB approval V2^active=false');
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');
inc.addEncodedQuery('workflow_versionLIKEEmployee Knowledge^document_id='+current.sys_id);
inc.orderBy('sys_created_on');
inc.query();
while(inc.next())
{
deletecount = deletecount++;
if (deletecount<wcounts)
inc.deleteRecord();
}
Second time i have tried with : But no reult
var wf =new GlideAggregate('wf_context');
wf.addEncodedQuery('workflow_versionLIKEKB approval V2^active=false');
wf.addEncodedQuery('workflow_versionLIKEEmployee Knowledge^document_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');
inc.addEncodedQuery('workflow_versionLIKEEmployee Knowledge^document_id='+current.sys_id);
inc.orderBy('sys_created_on');
inc.query();
while(inc.next())
{
deletecount = deletecount++;
if (deletecount<wcounts)
inc.deleteRecord();
}