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

Hi,

issue with syntax and script

function Cancelconfirm(){

var answer = confirm('are you sure you want to cancel?');

if(answer == true){
gsftSubmit(null,g_form.getFormElement(),'cancel');
}
else{
return false;
}

}

if(typeof window == 'undefined')
   cyclemove();

function cyclemove(){
current.phase='cancelled';
current.active=false;
current.update();
action.SetRedirectURL(current);
}

Regards
Ankur

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

Hi Ankur,

thanks for reply i tried same but when i select ok from confirmation box it won't cancel the request it just redirect to previous page

 

Hi,

please check the field name phase is proper and the value as well

Also update as this

action.setRedirectURL(current);

Regards
Ankur

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

one question.. onclick is cancelconfirm and client checkbox is true.

is this correct??

also i tried with this above changes.. but request won't get cancelled.