Redirect user to external website on new tabe using onChange script but not working

trade_wala1
Tera Contributor

I am currently building a Catalog item and I want user to be redirected to an external website (e.g. Microsoft.com) if they select no in the group_hr variable question which is select box type. The goal is to not let them submit the form if they are selecting no in that variable. Below is my script but it is not doing anything when i tested. Please assist:

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

// Check if the new value is 'no'
if (newValue == 'no') {
// Message with a clickable link
var message = 'Please click <a href="https://www.microsoft.com" target="_blank">here</a> to get more information about this access.';

// Show message
g_form.showFieldMsg('group_hr', message, 'info');

// Redirect
top.window.open = "https://www.microsoft.com/";
}
}

 

I have tried window.location.href for redirect but no luck. It's also not displaying any messages that's in the code.

19 REPLIES 19

@trade_wala1 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@trade_wala1 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@trade_wala1 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Shruti
Mega Sage
Mega Sage
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if (newValue == 'No') {
        // Message 
        var message = 'Please go to "https://www.microsoft.com" to get more information about this access.';

        // Show message
        g_form.showFieldMsg('group_hr', message, 'info');

        // Redirect
        top.window.open("https://www.microsoft.com/", '_blank');
    }

}

Hi Shruti,

Thanks for the update but I am not sure what's wrong as it doesn't work. I have UI policy on that variable which I have deactivated and there appears to be no conflict but still. There's no response on the CI when I change the group_hr value to no.