Cancel change with user Confirm Alert UI Action

JahanzebB
Mega Guru

SN Team,

In the process of modifying an existing Cancel Change UI Action. The goal is for the new UI Action to provide an confirmation window before proceeding with the Cancel Change request.

I have reviewed the following articles and here is what I came up.

Reference 1:

https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

Reference 2: Re: Cancel confirm window after clicking cancel button

Main issue: Confirmation window opens fine and allows user to Cancel. Having trouble getting the Cancel Change request to execute when OK is selected.

Looking for some help figuring out how to get the moveToCancel(); function to execute.

//moveToCancel();

//confirmCancel();

function confirmCancel(){

      var answer=confirm("Are you sure you want to cancel this record?");

      if (answer==false)

              {

              // gsftSubmit(null, g_form.getFormElement(), 'cancel_change');         //MUST call the 'Action name' set in this UI Action

                alert('This change was not cancelled');

              return false;      

              }

     

     

      else

          {

              moveToCancel();

              return true;

      }

}

function moveToCancel(){

      action.setRedirectURL(current);

      if (new ChangeRequestStateHandler(current).moveTo("canceled"))

              current.update();

}

      }

Thanks,

Jahanzeb

1 ACCEPTED SOLUTION

Deepak Ingale1
Mega Sage
  1. function confirmCancel(){  
  2.       var answer=confirm("Are you sure you want to cancel this record?");  
  3.       if (!answer)  
  4.               {  
  5.                 alert('This change was not cancelled');  
  6.               return false;          
  7.               }  
  8.       else  
  9.           {  
  10.               gsftSubmit(null, g_form.getFormElement(), 'cancel_change');         //MUST call the 'Action name' set in this UI Action  
  11.       }  
  12. }  
  13.  
  14. function moveToCancel(){  
  15.       action.setRedirectURL(current);  
  16.  
  17.       if (new ChangeRequestStateHandler(current).moveTo("canceled"))  
  18.               current.update();  
  19. }  

View solution in original post

16 REPLIES 16

that's correct

please share UI action screenshot

your function name should be same Cancelconfirm()

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

function name is same as you mentioned but i can see that its not setting request to cancelled phase and and making it active false.