I want to cancel the activity in workflow based on wf_context and wf_excuting table using runscript?

Santhosh15
Tera Guru

Hello all,

 

I need some help for cancelling one activity which was the second workflow for ritm. when i trigger the second workflow and trying to cancel based on conditions but its not getting cancelled. Can anyone please help me on this issue.

 

It STILL gives me the original workflow_context and not the currently executing one, even though printing out the value.

 

Santhosh15_0-1726225464933.png

This is the second workflow, when executing to cancel the activity its taking to first workflow activities.

 

Executed flow workflow:

Santhosh15_0-1726228904998.png

 


Script updating below:

var wf = new GlideRecord("wf_context");
wf.addQuery('sys_id', current.context);
wf.query();
gs.log('TESTING SANTHOSH:' + current.context);
while (wf.next()) {
    gs.info('inside while loop' + wf.sys_id);
    var wfe = new GlideRecord("wf_executing");
    wfe.addQuery('context', wf.sys_id);
    wfe.addQuery(activity.getDisplayValue(), "10mins");
    gs.info('after get activity' + wfe.getRowCount());
   // var qc = wfe.addQuery('activity_index', 5);
    //qc.addOrCondition('activity_index', 5);
    wfe.query();
   // gs.info('Index checking' + qc);
    while (wfe.next()) {
        gs.info('cancelled while loop inside' + wfe.sys_id);
        wfe.state = 'cancelled';
        wfe.update();
    }
}
 
Thanks in advance!!!!
1 REPLY 1

Mani A
Tera Guru

var wfContext = new GlideRecord('wf_context');
wfContext.addQuery('sys_id', current.context); 
wfContext.query();

while (wfContext.next())

{

var wfActivity = new GlideRecord('wf_executing');
wfActivity.addEncodedQuery('context='+wfContext.sys_id+'^activity.name=10mins^state=waiting);
wfActivity.query();

if (wfActivity.next()) {

  wfActivity.state = 'cancelled';
  wfActivity.update();

}
}