OnSubmit Client Script (Spmodal Scripting)

Luis Roman1
Tera Contributor

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.

LuisRoman1_0-1665309847609.png

 

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

3 REPLIES 3

Pavan Angadi
Tera Expert

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

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. 

LuisRoman1_0-1665309755965.png

Any other suggestion?

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