- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2019 11:46 PM
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:
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2019 06:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2019 11:52 PM
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://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
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2019 11:56 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2019 12:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2019 12:37 AM