top of page

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,080 per month

Opening Links in a New Window or Tab from ServiceNow UI Actions




When developing within ServiceNow, you might encounter scenarios where a UI Action, such as a button click, needs to open a specific URL or resource. While server-side scripting in UI Actions can easily redirect the current page, the requirement to open the link in a new browser window or tab presents a unique challenge. This article will delve into why a purely server-side approach is insufficient for this task and guide you through the correct method to achieve this functionality, ensuring a seamless user experience within your ServiceNow instance. This is particularly relevant for developers and administrators who need to link out to external resources or display content without disrupting the user's current workflow.


Let's say you have a UI Action in ServiceNow that, upon being clicked, should open an image or another web page in a new browser tab. Your initial instinct might be to use the action.setRedirectURL() method within the server-side script of the UI Action, providing the desired URL. While this will indeed redirect the user, it will do so within the same browser window or tab, potentially causing them to lose their current context within ServiceNow.


The Limitation of Server-Side Redirection


It's crucial to understand that server-side code, by itself, cannot dictate how the user's browser handles a redirection request in terms of opening new windows or tabs. The server's role is to send instructions to the browser about the next page to display. The decision of whether to open this in the current window or a new one lies with the browser itself, often based on user settings or the way the initial request was made. Allowing a server to arbitrarily open new tabs or windows on a client's computer would pose significant security risks.


The Solution: Combining Client-Side and Server-Side Logic


To successfully open a new window or tab from a ServiceNow UI Action, you need to employ a combination of server-side and client-side scripting. The recommended approach involves the following steps:

  1. Create a Client-Callable Script Include: This Script Include will contain the server-side logic to fetch the necessary URL or data. It will be called from the client-side.

    JavaScript



  1. Create a Client Script (associated with the UI Action or the form): This client script will trigger when the UI Action is clicked. It will use GlideAjax to call the Script Include and then use client-side methods to open the URL in a new tab.

JavaScript



Important Note: The original community post mentioned using g_list.getChecked() in the client script. This indicates that the UI Action was likely operating on a list of records, and the user wanted to open an image associated with the selected records. You'll need to adapt the client script to correctly identify the targetSysId based on your specific UI Action's context (e.g., using g_form.getUniqueValue() for a form UI Action or g_list.getChecked() for a list UI Action).


  1. Configure the UI Action:

Ensure the "Client" checkbox on the UI Action form is checked.

In the "OnClick" field, call the client-side function you created (e.g., onClick()).

You might also need a server-side script in the "Script" field of the UI Action to handle any server-side logic that needs to occur before or after opening the new tab (though for simply opening a URL, the client-side approach is primary).


How it Works


When the user clicks the UI Action, the client script executes. This script uses GlideAjax to make an asynchronous call to the getUrlForNewTab function in the OpenNewTabUtil Script Include. The Script Include then performs the necessary server-side logic to determine the URL (e.g., fetching the sys_id of an attachment). The URL is returned to the client script, which then uses g_navigation.openPopup(url) to instruct the browser to open the URL in a new window or tab. g_navigation.openPopup() is a ServiceNow-supported client-side API for opening new browser windows or tabs.


Practical Examples and Use Cases


  • Opening a detailed view of a related record in a new tab without navigating away from the current record.

  • Displaying a knowledge base article or external documentation in a separate tab for easy reference.

  • Launching a third-party application or website from a ServiceNow record.


Alternative Solutions (and Why Server-Side Alone Fails)


As highlighted earlier, a purely server-side action.setRedirectURL() will not open a new tab. While some older web development techniques might involve server-side headers to suggest opening in a new window, these are generally unreliable and not the standard practice in modern web applications, especially within a framework like ServiceNow. The client-side control is essential for this specific requirement.


Conclusion


Opening a new window or tab from a ServiceNow UI Action requires a combined approach of server-side logic (within a Client-callable Script Include) and client-side scripting (using GlideAjax and g_navigation.openPopup()). This method respects browser security protocols and provides a reliable way to navigate users to new content without disrupting their current ServiceNow session. The key takeaway is that server-side code alone cannot dictate browser behavior for opening new tabs, and leveraging client-side capabilities is necessary to achieve this common user experience requirement. The next step is to implement this two-part solution for your specific UI Actions that need to open links in new windows or tabs, ensuring you adapt the code to your particular use case and data structures.

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,080 per month

CONTACT

New Zealand HQ

Integrated Knowledge Consulting Office

Level 3, 93 Grafton Road

Auckland

South Korea

Integrated Knowledge Consulting Office

BMY역삼타워 6층

서울특별시 강남구 역삼동 678-10번지

 

info@ikconsulting.com

Thanks for submitting!

  • LinkedIn Social Icon

© Copyright 2025 Integrated Knowledge Consulting. All rights reserved.

bottom of page