Redirect user to external website on new tabe using onChange script but not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2025 10:14 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2025 10:33 PM
you want to open in new tab that link or simply show it to users?
we can't add link using showFieldMsg
why not show them the link in info message
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.addInfoMessage(message);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2025 10:37 PM
if you wish to open that link in new tab and also show the message then do this
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
// Show message
g_form.addInfoMessage(message);
// Redirect
top.window.open("https://www.microsoft.com/", "_blank");
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2025 10:46 PM
Hi Ankur,
I have tried my above script and updated to yours but it doesn't do anything. When i go to test catalog item and select no from drop down, there's no redirection or any error message on browser.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2025 11:02 PM
please share your latest script
I am able to get the info message
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader