Cancel Request UI Button

Anna L
Tera Contributor

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?

1 ACCEPTED SOLUTION

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);


}



ui.PNGUI1.PNG


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


View solution in original post

12 REPLIES 12

Manik
ServiceNow Employee
ServiceNow Employee

Hi,



You can create UI Action on Task form by using the following link:



UI Actions - ServiceNow Wiki



In UI Action you can script using a Glide Dialog Window for displaying a popup with warning message required in a UI Page, for reference you can use below link:



Displaying a Custom Dialog - ServiceNow Wiki



You can also create a Client Side UI Action and display the warning message using a alert statement if you don't want to use a dialog window.



Please let me know if it answers your question and helps.



Thanks,


Manik



PS - Please mark correct, helpful and like if applicable.


Anna L
Tera Contributor

Hi Manik,



Thanks. I am not very good in scripting. Can you guide me how would I accomplish this?


Abhinay Erra
Giga Sage

Hi,



  What is your   use case here other than popup message?



Thanks,


Abhinay



PS: Hit like, Helpful or Correct depending on the impact of the response


Anna L
Tera Contributor

The use case, if for some reason, the itil user says task cannot be completed and want to cancel the request completely, they should have a UI button to do so. When they do, a popup message should be there to say them "if you cancel request, workflow will be stopped"