UI action to cancel workflow and close complete RITM and not spawn any followed tasks

Sam198
Mega Guru

Hi all,

I have this UI action button where it should close the current sctask and ritm and it should cancel the workflow so that it does not spawn the follow up sctask (as there is one in the workflow). The closure of current sctask and ritm is working however, the following sctask/workflow is not cancelling:

UI action table: sc_task

script:

function cancelTask(){

if(confirm('Are you sure you want to close complete this request?')){
gsftSubmit(null, g_form.getFormElement(), 'cancel_sc_task');
return true;

}
return false;
}

// Server side code
if(typeof window == 'undefined')
updateTaskAndRITM();
function updateTaskAndRITM(){
new Workflow().deleteWorkflow(current);
current.active=false;
current.state=3;
current.update();
action.setRedirectURL(current);

var reqItem = new GlideRecord('sc_req_item');
new Workflow().deleteWorkflow(current);
reqItem.get(current.request_item);
reqItem.state = 3; //value for Closed complete
reqItem.stage = 'Completed';
reqItem.update();

new UIActionUtils().approvalsNoLongerRequired(current.sys_id);


}

 

This circled sctask still spawns that should not have spawned:

 

find_real_file.png

1 ACCEPTED SOLUTION
5 REPLIES 5

AbhishekGardade
Giga Sage

Hello sam,

1. use below line to cancel Workflow.

new Workflow().cancel(current);

new Workflow().deleteWorkflow(current); // I have found it better to have this line at the top (start) of the script for it to work correctly.

and to cancel approvals

new WorkflowApprovalUtils().cancelAll(current, comment);

 

Check out referenc documents:

https://www.servicenowguru.com/scripting/business-rules-scripting/canceling-executing-workflows-task...

https://developer.servicenow.com/app.do#!/api_doc?v=london&id=r_WF-cancel_GR 

2. Check below line in your code:

reqItem.stage = 'Completed'; // check value of Completed

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

Hi Abhishek,

I tried with that but still same - it still spawns the second sctask that is part of the workflow.

Thanks for the reply.

Hello Sam,

What is this? reqItem.stage = 'Completed';

Try commenting that line. I dont see any field available on sc_task.


Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

That's for setting the stage for RITM:

 

find_real_file.png