- 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
09-18-2015 10:12 PM
Hi Jessica,
One way of doing this is by using global UI scripts.
From which form or related list are you opening this "Edit Members" page?
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2015 02:36 PM
Hi Berny - The 'Edit Members' page aka sys_m2m_template is the oob Group Members related list. I don't know how, or if it's even possible, to access the sys_m2m_template page as I can't find it under the UI pages.
- 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
09-28-2015 01:08 PM
Hi Berny, I tested it out and it worked great! Now I just have to think up a message to add since it'll appear even if they click Save. It's too bad I can't use g_form.getActionName() method and then customize the message based on if they click save or cancel. But what you gave me will work so thanks for all your help!