OnSubmit Client Script (Spmodal Scripting)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2022 02:20 PM - edited 10-09-2022 03:05 AM
My knowledge in scripting is limited. However, what I am trying to do is when a request is submitted a pop up will be display with two buttons (Yes and No). Then is Yes is click I want to re-direct to a url or if No is click then want to re-direct to a different URL.
The script that I am working is not working is below.
function onSubmit() {
if (typeof spModal != 'undefined' && !g_form._hasConfirmed) {
spModal.open({
message: 'Do you want to submit Hardware Return?',
title: 'Employee Certification',
buttons: [
{label:'✔ Yes', cancel: true},
{label:'✘ No', primary: true}
]
}).then(function(confirm){
if (confirm){
var redirectURL1 ='https://dev101621.service-now.com/sp?id=index';
top.window.location = redirectURL1;
}
var redirectURL ='https://dev101621.service-now.com/sp?id=index';
top.window.location = redirectURL;
}
);
return false;
}
}
What I need to figure out is how can I determine which option selected then able to redirect to the appropriate URL. Therefore, your expert advise or assistance will be appreciated.
Luis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2022 03:01 PM
Hi Luis,
You can use below script in onsubmit client Script.
On Click of Yes/No, url's will be opened in new window and the existing records is saved.
function onSubmit() {
var response = confirm("Do you want to submit Hardware Return?");
if (response) {
var redirectURL1 = 'https://dev101621.service-now.com/sp?id=index';
g_navigation.open(redirectURL1, '_blank');
} else {
var redirectURL = 'https://dev101621.service-now.com/sp?id=index';
g_navigation.open(redirectURL, '_blank');
}
}
Best Regards,
Pavan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2022 07:23 PM - edited 10-09-2022 06:17 AM
Pavan thank you for the feedback. However, when I tried it I get an error in the console. The error is "There is a JavaScript error in your browser console". In addition, your suggestion does not work with the spmodal which we would like to use in order to have a better user experience.
Any other suggestion?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2022 02:07 PM
Hi Luis,
Kindly try below code, hope this helps.
function onSubmit() {
spModal.open({
"title": "Disclaimer",
"message": "disclaimer msg.",
"buttons": [{
label: "✔ State",
primary: true
},
{
label: "✘ Return to form",
cancel: true
}
],
"backdrop": "static",
"keyboard": false
}).then(function() {
var redirectURL = 'https://www.google.co.in';
top.window.open(redirectURL);
}, function() {
var redirectURL = 'https://www.google.com';
top.window.open(redirectURL);
})
}
Thank you,
Pavan