- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2015 08:46 AM
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!
.
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.';
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2015 09:25 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2017 07:56 PM
Hi Berny,
Is it possible to give custom message in the prompt instead of the message if you want to leave this stie?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2017 04:37 AM
Hi Karteek,
Indeed, you can use "alert". That will bring a popup with a message you want to display to the user.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2017 05:02 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2017 07:33 AM
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 -:
Would like to know what can be done to have this popup without getting the blank screen.
Regards,
Prasad M K