- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2016 11:50 AM
Is it viable to have Cancel Request UI Button on Task form and Request Item form and once the user clicks the button, a message should popup as a warning. How would you do it? Any suggestions?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2016 03:02 PM
You will have to add a client side code to UI action. I have just added the popup message to the OOB UI action 'Cancel request'
Here is the script for that
function cancelRequest(){
var submitFlag= confirm("If you cancel request, workflow will be stopped");
if(!submitFlag){
return false; //Abort submission
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'cancel_request'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode(){
current.request_state = 'closed_cancelled';
current.update();
new UIActionUtils().approvalsNoLongerRequired(current.sys_id);
}
This link will be helpful on how to write both client side and server side code in a single UI action
Client & Server Code in One UI Action - ServiceNow Guru
Thanks,
Abhinay
PS: Hit like, Helpful or Correct depending on the impact of the response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2018 07:30 PM
Hi There,
I've followed this, but need to modify it to
1. Check if there are any open SCTASK and if so, stop ability to cancel
2. If cancelling, automatically change to workflow stage to 'complete' The workflow stage currently stays in the pre cancelled state, even though the RITM is cancelled
My script is similar - I'm just not sure how to add these additional requirements. Any help would be appreciated:
function cancelRequest(){
if(confirm('Are you sure you want to cancel your Request?')) {
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'cancel_request');
}
return false;
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
updateTaskAndRITM();
function updateTaskAndRITM(){
current.state = 4; //value for Closed incomplete
current.work_notes = 'Request Cancelled';
current.comments = 'This request been cancelled';
current.update();
var reqItem = new GlideRecord('sc_req_item');
reqItem.get(current.request_item);
reqItem.comments = 'Request Cancelled';
reqItem.work_notes = 'Request Cancelled';
reqItem.state = 4; //value for Closed incomplete
reqItem.update();
new UIActionUtils().approvalsNoLongerRequired(current.sys_id);
current.stage = 'Completed';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2020 06:16 AM
Hi Anna,
Did you find the solution, is system able to cancel all the associated RITM's and ScTask cancelled when request is cancelled.
Thanks, Jay

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2020 05:05 PM
Hi Jay,
I've moved on to another company now, so don't have access to the environment anymore. From memory I think we changed our requirements and created a cancel button on the portal ticket widget, allowing end users the ability to cancel their own requests. It also cancelled the associated workflow, underlying tasks.
Cheers,
Anna