Confirm box on a ServerSide/Client Side UI Action

Stacy1
Mega Guru

I have a UI action that is a Client side and Server Side.   I already have an onClick defined for the UI action.   However, my user's want a confirmation box to popup asking if they are sure they want to complete the action.  

Does anyone know how I can do this?

Thanks,

Stacy

1 ACCEPTED SOLUTION

ccajohnson
Kilo Sage

Within your on-click script add something like the following:



      var usrResponse = confirm('Are you sure you want to do Something?');


      if (usrResponse == true) {


              DO THE REMAINDER OF YOUR SCRIPT HERE


        } else {


              return false


      }


View solution in original post

4 REPLIES 4

Shishir Srivast
Mega Sage

Hi Stacy,



You can have something like below in your onClick on client side to get confirmation from user to proceed further.



      var answer=confirm("Are you sure you want to complete the action?");


      if (answer==true)


              {


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


      }


      else


              {


              return false;


      }


ccajohnson
Kilo Sage

Within your on-click script add something like the following:



      var usrResponse = confirm('Are you sure you want to do Something?');


      if (usrResponse == true) {


              DO THE REMAINDER OF YOUR SCRIPT HERE


        } else {


              return false


      }


kalyansiva
Kilo Contributor

Hello stacy,



you can write something like


on UI action ::onclick : myClientSideFunction()



script::


function myClientSideFunction(){


if(confirm("Are you sure you want to perform this action?")){


gsftSubmit(null,g_form.getFormElement(),'actionnamevalue');


}else{


return false;


}


}


if(typeof window == 'undefined'){


                myServerSideFunction();


}


function myServerSideFunction(){


your server side logic what ever you wanna write;


}






Please mark it helpful or correct if it fulfills the request.


Thanks.


asit2
Kilo Expert

You can go through the wiki article- Scripting Alert, Info, and Error Messages - ServiceNow Wiki



You can write an onsubmit client script-


find_real_file.png



Script code:-


function onSubmit() {


    var ConfirmOrNot=confirm("Do you want to submit?");


      if (ConfirmOrNot==true)


              {


return true;


              }


      else


              {


              return false;


              }


}