Is it possible to add a dirty form alert popup to sys_m2m_template?

uluerje
Mega Expert

I have a request to add a popup message to the "Edit Members" page (sys_m2m_template - seen below) that will alert the user that their changes have not been saved if they accidentally press the back button or try to navigate away from the page without saving.   Does anyone know if this is possible?   I got an onLoad script off the guru site but just don't know where to put it.   Thanks!

Slushbucket-Normal-300x216.jpg.

function onLoad() {

    //Add the 'onbeforeunload' event

    window.onbeforeunload = function() {

          //If we're leaving a modified form without a submit

          if (!g_form.submitted && g_form.modified) {

                //Add the custom dialog message here

                return 'YOUR CUSTOM MESSAGE HERE.';

          }

    }

}

1 ACCEPTED SOLUTION

Hi Jessica, you can create a UI script which is global and have a code like the following:



function validateFunc(){  


  try{


          if (window.location.href.indexOf('sys_m2m_template.do') != -1){


                  window.onbeforeunload = function() {


                          // Do your validation here.


                          // If it returns false then the ServiceNow will prompt the message if you want to leave or stay


                  }


          }


  }


  catch(e){}


}



addAfterPageLoadedEvent(validateFunc);



The one disclaimer is that i don't think that g_form will be available when you access sys_m2m_template.do. You may will need an alternative.



Here are some thoughts on that:



a) you may want to check if the sluchbucket list has changed by using it's element id


b) always prompt (force) the users to validate if they have saved the changes.


c) Always save any changes and perhaps include a message (just a label) to the users so that they're aware that this is the case.


d) a combination of the above



I hope this is helpful!



Thanks,


Berny


View solution in original post

8 REPLIES 8

Hi Berny,



Is it possible to give custom message in the prompt instead of the message if you want to leave this stie?



Thanks!



Hi Karteek,



Indeed, you can use "alert". That will bring a popup with a message you want to display to the user.



Thanks,


Berny


Hello All,



I had a requirement to add Check box to the Alert popup window and disable the OK Button when sys_m2m_template.do gets opened.



So would like to know how this can be achieved or is there any way how we can display pop up window to the user once sys_m2m_template.do gets opened.



Thank you in advance.



Regards,


Prasad M K


meprasu
Kilo Explorer

Hello Everyone,



I have created a Global UI Script which would pop up Confirmation Dialog box when users clicks on Edit button to add Group Members.



My concern is when this window is popped up previous screen gets blank as shown below -:



Pop_up.JPG



Would like to know what can be done to have this popup without getting the blank screen.



Regards,


Prasad M K