Redirct in a client script

ServNowDev
Tera Guru
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,

4 REPLIES 4

Sumanth16
Kilo Patron

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

Danish Bhairag2
Tera Sage
Tera Sage

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

Aman Kumar S
Kilo Patron

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

 

 

Best Regards
Aman Kumar

Maddysunil
Kilo Sage

@ServNowDev 

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