Redirct in a client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 01:46 PM
function onLoad() {
if (g_form.isNewRecord()) {
if (confirm('This request is for a Manual submission ,Please confirm you would like to proceed')) {
return true;
} else {
return false;
}
}
I have an onload client script when you open for a new record it lets your know that you need to confirm to proceed, is there a way if it is cancelled selected it will redirect to the servicenow main page,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 02:04 PM
Hi @ServNowDev ,
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// If you want redirection based on certain conditions then you can have your if-else statements here.
alert("You will be redirected");
top.window.location = "https://www.google.com/ "; // Change URL Based on your requirements.
//Type appropriate comment here, and begin script below
}
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 06:18 PM
Hi @ServNowDev ,
U can add below logic of they have selected cancel
var redirectURL = 'https://www.google.com/'; //url to redirect; this approach works in platform and Service Portal view
top.window.location = redirectURL ;
}
Thanks,
Danish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 07:23 PM - edited 02-15-2024 07:28 PM
Hi @ServNowDev
You need to write up below script:
if (g_form.isNewRecord()) {
var checkResponse = confirm('This request is for a Manual submission ,Please confirm you would like to proceed'));
if(checkResponse == "false"){
top.window.location = "/sp";// or any other URL you want
}
}
Ref SN article:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0724129
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0715914
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 07:28 PM
Please try below code
function onLoad() {
if (g_form.isNewRecord()) {
if (confirm('This request is for a Manual submission. Please confirm if you would like to proceed.')) {
return true;
} else {
// If the user cancels, redirect to the ServiceNow main page
window.location.href = “www.”google.com; // Replace with your ServiceNow main page URL
return false;
}
}
}
Kindly mark helpful/accepted if it helps you.
Thanks