- 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
‎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
‎06-26-2016 03:51 PM
Hey Abhinay,
This works seamlessly, but on request form. What if user can see the same UI button on task itself, do you see that being possible and good practice use case?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2016 04:18 PM
If you want that UI action on the catalog task or request item, you will have to duplicate the UI action and change the table to sc_task and sc_req_item instead and you need to slightly tweak your code in the UI action
Instead of current.request_state = 'closed_cancelled'; add this in UI action current.request.request_state='closed_cancelled';
Don't forget to mark it as correct.
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
‎07-13-2018 04:28 PM
Hello Abhinay,
Have you done this within a Service Portal catalog widget? So from the Service Portal, the user has a 'Cancel' button on the widget that cancels the request. Excuse me if there is a widget to build off from but I have seen any OOB Widgets that have this functionality or something like it.
Thank you,
-Wesley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2018 12:52 PM
I'm new to scripting in SN as well and wondering where this functionality is at?? Is there supposed to be a form button on the Request itself?? in SP?