How to delete a record in "Workflow Context" when we click on UI Action

chanikya
Kilo Sage

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.

find_real_file.png

find_real_file.png

find_real_file.png

Employee Knowledge -workflow

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

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.

View solution in original post

15 REPLIES 15

Can you tell me, when you run kbapproval v2 and Employee Knowlege. What is the reason behind having 2 workflows?


The conditions doesnt make sense



Please mark this response as correct or helpful if it assisted you with your question.

Hi Sanjiv,



first workflow- KBapprove is only taking approves ,   once KB record is approved then state is moved to Published .



Second Workflow- Employee KB


find_real_file.png



find_real_file.png


find_real_file.png


find_real_file.png



once it is retired after 6 months state is going to End.


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.

Hi Sanjiv,




it was in emergency situation , Really thank you for it.



it is working fine, Thank you so much SANJIV..!!


i request you , if i have any kind of issue in this thread , can i reach out you ??



i request your help here please..