What is the Glide Navigation API? Your Guide to Seamless User Journeys in ServiceNow
Ever found yourself wanting to open a specific record, a related list, or even an external website right from a ServiceNow form or list, all with a single click? Or perhaps redirect users automatically after they complete an action? If you’re nodding your head, then you’re in the right place! Today, we’re going to pull back the curtain on a truly handy, client-side gem within the ServiceNow platform: the Glide Navigation API.
For many new developers and even some seasoned pros, the intricacies of navigating within ServiceNow can sometimes feel like a maze. But with the Glide Navigation API, specifically through its global object g_navigation, you gain a powerful set of tools to control how and where your users go. It’s about more than just opening a new tab; it’s about crafting a smoother, more intuitive user experience, saving clicks, and automating the mundane. Let’s dive in!
Unpacking the “Glide Navigation API” – What Exactly Is It?
Let’s break down this somewhat formal-sounding name into something a bit more digestible. When we talk about the “Glide Navigation API,” we’re primarily referring to a JavaScript object available on the client side in ServiceNow, aptly named g_navigation. Think of it as your personal browser chauffeur within the ServiceNow ecosystem.
The Core Concept: Taking Control of the Browser Tab
At its heart, the Glide Navigation API provides a programmatic way to handle URL navigation. Instead of a user manually copying a URL, opening a new tab, and pasting, you can script this entire process. It allows you to direct users to specific pages, records, lists, or even external websites, all triggered by an event on the current page. This isn’t just about convenience; it’s about building intelligent, responsive interfaces that anticipate user needs.
Where Does g_navigation Fit In?
In ServiceNow, the g_ prefix typically denotes a global JavaScript object that’s part of the platform’s client-side API. Just like g_form lets you interact with form fields, or g_user gives you details about the current user, g_navigation empowers you to manage browser navigation. It’s part of the extensive toolkit ServiceNow provides for building dynamic and interactive experiences.
Why is “Client-Side” So Important Here?
The reference content explicitly states this API can “be used only at the client side.” This is a crucial distinction. “Client-side” means the code runs directly in the user’s web browser (e.g., Chrome, Firefox, Edge) after the page has loaded. It doesn’t execute on the ServiceNow server. Why does this matter?
- Responsiveness: Client-side actions are typically much faster because they don’t require a round trip to the server. The browser can react instantly.
- User Interface (UI) Interaction: Since it’s running in the browser, client-side code has direct access to browser functionalities like opening new tabs or redirecting the current one.
- Security Implications: You generally can’t perform heavy data manipulation or sensitive server-side operations with client-side code alone. It’s focused on UI and browser interactions.
- Context: It operates within the context of the currently loaded page and the user’s browser session.
So, when you use g_navigation, you’re essentially telling the user’s browser, “Hey, when this button is clicked, or this condition is met, open *this* URL for me!”
Why You Need the Glide Navigation API: Real-World Scenarios
Now that we know what it is, let’s talk about why you, as a ServiceNow developer or administrator, would actually want to use this API. It’s not just a fancy trick; it’s a practical tool for solving common workflow and user experience challenges.
Enhancing User Experience: No More Manual Copy-Pasting!
Imagine a scenario where an agent is working on an Incident and needs to quickly reference a related Knowledge Base article, a Problem record, or even an external vendor’s documentation. Without g_navigation, they might have to copy an ID, use the search bar, or navigate through multiple modules. With g_navigation, you can add a simple button or link that, when clicked, instantly opens the relevant item in a new tab, keeping their current work context undisturbed. This reduces cognitive load and saves valuable time.
Streamlining Workflows: Automating Inter-Record Navigation
Consider a custom application where creating a new “Project Task” automatically generates a related “Resource Request.” After the task is created, instead of leaving the user on the Project Task form, you could automatically redirect them to the newly created Resource Request form to fill in the details. This kind of guided workflow keeps users focused and reduces the chances of them getting lost or missing a crucial step.
Another common use case is when you have a UI Action that creates a new record. After the record is created, you often want to show the user the new record. g_navigation allows you to redirect to the new record’s form directly.
Building Dynamic Dashboards and Custom UI Actions
If you’re building custom UI Pages, Widgets, or UI Actions, g_navigation becomes an indispensable tool. You can create buttons that:
- Open a filtered list of records (e.g., “Show all open Critical Incidents”).
- Direct users to a specific module or page within the platform.
- Launch an external reporting tool or a SharePoint document library relevant to the current record.
It gives you the power to break free from standard navigation patterns and create highly tailored, efficient user interfaces.
Security and Control: Opening Specific Content
While g_navigation facilitates opening various URLs, it also inherently offers a degree of control. Instead of giving users a generic link that might lead them astray, you can script specific, validated URLs. This ensures users are always directed to the correct, intended content, whether internal or external, reducing misdirection and potential security risks from mistyped URLs.
Getting Started with g_navigation: Practical Usage
Alright, enough theory! Let’s get our hands dirty and see how to actually use this powerful API. Remember, we’re talking client-side scripting, so you’ll typically be writing this code in Client Scripts, UI Actions (with the “Client” checkbox checked), or even directly within UI Pages/Widgets.
The Basic Syntax: How to Call It
The g_navigation object is globally available, so you simply call its methods directly. There are a few key methods that handle different navigation scenarios.
Key Methods and Their Power
g_navigation.open(url, target): The Workhorse
This is arguably the most frequently used method. It opens a specified URL in a new window or tab, or in the current window, depending on the target parameter. It’s very similar to how an HTML <a> tag with target="_blank" behaves.
url(String, required): The URL you want to navigate to. This can be a relative path within ServiceNow (e.g.,'incident.do?sys_id=' + g_form.getUniqueValue()) or a full external URL (e.g.,'https://www.google.com').target(String, optional): Specifies where to open the URL.'_blank'(default): Opens the URL in a new browser tab or window. This is generally preferred to keep the user’s current context.'_self': Opens the URL in the current browser frame.'_parent': Opens the URL in the parent frame.'_top': Opens the URL in the full body of the window.- You can also specify a named window (e.g.,
'myCustomWindow'). If a window with that name exists, the URL opens there; otherwise, a new window with that name is created.
g_navigation.openPopup(url, width, height): For Dialogs
This method is excellent for opening a URL in a new, smaller pop-up window, often used for quick lookups, secondary information, or a temporary interaction without fully navigating away from the main page.
url(String, required): The URL to open in the pop-up.width(Number, optional): The width of the pop-up window in pixels (e.g.,800).height(Number, optional): The height of the pop-up window in pixels (e.g.,600).
Be mindful of browser pop-up blockers when using this, as they can sometimes interfere.
g_navigation.redirect(url): Staying in the Same Tab
If you want to navigate the user to a new URL within the same browser tab or window, completely replacing the current page, redirect() is your go-to. It’s essentially equivalent to setting window.location.href = url; but often preferred for consistency within the ServiceNow client-side ecosystem.
url(String, required): The URL to redirect to.
Crafting Your URLs: What Can You Open?
The beauty of these methods is their flexibility in the types of URLs they can handle:
- Internal ServiceNow Pages (Forms, Lists, Modules):
- A specific record:
'incident.do?sys_id=YOUR_SYS_ID' - A filtered list:
'incident_list.do?sysparm_query=active%3Dtrue%5Epriority%3D1' - A module:
'nav_to.do?uri=incident_list.do' - A specific portal page:
'/sp?id=my_custom_page'
- A specific record:
- External Websites:
'https://www.servicenow.com''http://yourcompanydocumentation.com/page.html'
- Scripted Pages (UI Pages):
'your_ui_page_name.do'
Live Demos and Examples (Code Snippets)
Let’s look at some practical examples you can implement.
Example 1: Opening a Related Record in a New Tab (UI Action on Incident form)
Imagine you have a custom field on the Incident form, u_related_problem, which references the Problem table. You want a UI Action button to quickly open that Problem record.
// UI Action (Client-side, OnClick handler)
// Name: Open Related Problem
// Table: Incident [incident]
// Client: checked
// OnClick: openRelatedProblem();
function openRelatedProblem() {
var problemSysId = g_form.getValue('u_related_problem');
if (problemSysId) {
var url = 'problem.do?sys_id=' + problemSysId;
g_navigation.open(url, '_blank'); // Open in a new tab
} else {
g_form.addInfoMessage('No related Problem record found.');
}
}
This script checks if a Problem is linked, constructs the URL, and uses g_navigation.open() to pop it open in a fresh tab.
Example 2: Redirecting After Form Submission (Client Script or UI Action)
Suppose you have a custom ‘Request Access’ form. After submission, you want to redirect the user to a confirmation page or their ‘My Requests’ list.
// Example 2.1: After form submission (e.g., in a Business Rule called from a Client Script or UI Action, though redirect is client-side)
// More typically, this would be in a Client-side UI Action "Submit and View"
// UI Action (Client-side, OnClick handler)
// Name: Submit and View Request
// Table: My Custom Request Table [u_my_request]
// Client: checked
// OnClick: submitAndRedirect();
function submitAndRedirect() {
// Save the record first (if it's a new record, the sys_id will be generated)
g_form.save(); // This typically refreshes the page or handles redirection based on UI Policy/Business Rules
// If you need to redirect *immediately* after a client-side save without a full page refresh
// This part is trickier as g_form.save() can be asynchronous or cause a reload.
// A better approach for new records is often to let the server-side Business Rule
// populate the sys_id, and then use g_navigation.redirect with the new sys_id
// or to redirect to a generic list.
// Let's assume a simpler case: Redirect to a general list after an action.
// Or, if working with a new record:
// This requires the sys_id of the *newly created* record.
// A better pattern for new record redirection:
// 1. UI Action (Client-side): Calls g_form.submit() with a custom action name.
// 2. Business Rule (Server-side, before insert/update): Creates the record.
// 3. Business Rule (Server-side, after insert): Sets a g_scratchpad variable with the new sys_id.
// 4. Client Script (onLoad): Checks g_scratchpad for the sys_id and redirects using g_navigation.redirect.
// A direct client-side example if the record is already saved or you want to redirect to a general list:
g_navigation.redirect('sp?id=my_requests'); // Redirect to the Service Portal "My Requests" page
// Or to an incident list:
// g_navigation.redirect('incident_list.do?sysparm_query=active%3Dtrue');
}
This simple call ensures the user seamlessly transitions to the next logical step in their workflow.
Example 3: Opening an External Link from a UI Action
Your company has an internal Confluence page for policy documentation. You want a button on the Change Request form to open the relevant policy.
// UI Action (Client-side, OnClick handler)
// Name: View Change Policy
// Table: Change Request [change_request]
// Client: checked
// OnClick: openPolicyDoc();
function openPolicyDoc() {
var externalUrl = 'https://wiki.yourcompany.com/pages/viewpage.action?pageId=12345';
g_navigation.open(externalUrl, '_blank');
}
No more digging through bookmarks or intranet searches!
Example 4: Using openPopup for Quick Lookups
You might have a custom form where users need to select a configuration item, but you want to provide a quick “details” view without interrupting their current form entry.
// Client Script (e.g., on a custom button or field change)
// Name: Open CI Details Popup
// Table: Your Custom Table
// Type: onChange (on a CI reference field) or onSubmit / UI Action
function openCIDetailsPopup() {
var ciSysId = g_form.getValue('cmdb_ci'); // Assuming 'cmdb_ci' is your reference field
if (ciSysId) {
var url = 'cmdb_ci.do?sys_id=' + ciSysId;
g_navigation.openPopup(url, 900, 700); // Open a 900x700 pixel popup
} else {
g_form.addErrorMessage('Please select a Configuration Item first.');
}
}
This allows for a non-intrusive way to view related information.
Troubleshooting Common Glide Navigation API Issues
Even with great tools, sometimes things don’t go as planned. Here are some common hurdles you might encounter with g_navigation and how to tackle them.
“Nothing Happens!”: Check Your Parameters
This is probably the most common issue. If your script runs but no new tab opens (or no redirect occurs), double-check:
- Is your URL valid? A malformed URL will simply fail to open. Test the URL directly in your browser first.
- Is the
sys_idcorrect? If you’re concatenating asys_id, ensure it’s actually populated and valid. - Are you calling the method correctly? Typos in
g_navigation.openor missing parentheses can stop things dead. - Is the script actually executing? Use
console.log("My script is running!");at the start of your function to confirm your UI Action or Client Script is being triggered.
“Access Denied!”: Browser Pop-up Blockers
When using g_navigation.open(url, '_blank') or especially g_navigation.openPopup(), modern web browsers are highly aggressive about blocking unsolicited pop-ups. If the call to g_navigation.open() isn’t directly triggered by a user action (like a button click), the browser might block it.
- Solution: Ensure the
g_navigationcall happens directly within an event handler, like theonClickof a UI Action or a button. If you’re trying to open a pop-up after an asynchronous operation (like an AJAX call), you might need to inform the user that a pop-up needs their permission or find an alternative navigation method. Users can also manually allow pop-ups for your ServiceNow instance.
“URL Not Found!”: Verify Your Path
If the new tab or window opens but shows a “Page Not Found” error, the URL itself is the culprit.
- Solution:
- For internal ServiceNow pages: Make sure table names (e.g.,
incident.do, notincidents.do), parameter names (sys_id,sysparm_query), and values are correct. - For external sites: Check for typos, missing
http://orhttps://, or incorrect domain names. - Use
console.log('Attempting to open URL: ' + url);right before yourg_navigationcall to see the exact URL being passed. Copy and paste that URL directly into a new browser tab to see what happens.
- For internal ServiceNow pages: Make sure table names (e.g.,
Cross-Browser Compatibility Concerns
While g_navigation is generally robust across modern browsers, slight behavioral differences can sometimes occur, particularly with pop-ups. Always test your navigation solutions in all the browsers your organization officially supports.
Debugging with Browser Developer Tools
Your browser’s developer tools (F12 or right-click -> Inspect) are your best friend.
Use them to:
- Check the Console: Look for JavaScript errors, which might indicate a syntax issue or a problem with your variables.
- Set Breakpoints: Step through your client-side code line by line to see the exact values of your variables (like the generated URL) just before the
g_navigationcall. - Network Tab: See if a navigation request was even initiated and what the response was (e.g., a 404 for a missing page).
Best Practices and Performance Considerations
Like any powerful tool, g_navigation comes with responsibilities. Use it wisely to maximize its benefits and avoid user frustration.
User Experience First: Don’t Overuse New Tabs
While opening new tabs can be great for preserving context, too many new tabs can quickly become overwhelming for users. Reserve '_blank' for when the user truly needs to keep their current page open for reference, or when navigating to an external site. For simple redirects within the same workflow, g_navigation.redirect() or '_self' might be more appropriate.
Accessibility: Inform Users About New Windows
If your script opens a new window or tab, it’s good practice, especially for accessibility, to either explicitly state this on the UI Action label (e.g., “Open KB Article (New Tab)”) or use an ARIA attribute if you’re building custom HTML. This prepares users for the change in context.
Performance: Keep Your Client Scripts Lean
While g_navigation itself is light, the client script it’s embedded in should follow best practices: minimize DOM manipulation, optimize any data lookups (e.g., using `GlideAjax` for server calls rather than large client-side lookups), and ensure your scripts aren’t running unnecessarily.
Security: Validate User Input for URLs
If your URL construction involves user input (e.g., from a text field), always validate and sanitize that input to prevent potential cross-site scripting (XSS) vulnerabilities. Never directly concatenate unvalidated user-provided strings into a URL without proper encoding or checks.
Interview Relevance: Mastering g_navigation
Understanding and being able to confidently explain and demonstrate the use of the Glide Navigation API can be a real asset in a ServiceNow developer or administrator interview. Here’s why:
- Demonstrates Practical Client-Side Scripting Skills: It shows you understand how to interact with the browser and enhance the UI using JavaScript within ServiceNow, which is a core skill.
- Shows Problem-Solving and UX Focus: Interviewers want to see that you can think about how to improve the user’s daily work. Discussing how
g_navigationcan streamline workflows or prevent users from getting lost showcases this. - A Niche but Powerful Tool in Your Arsenal: It’s not as common as
g_formorg_user, so knowing it well sets you apart. It indicates you’ve explored the platform’s capabilities beyond the basics. - Discussion Point for Best Practices: You can discuss when to use
open()vs.redirect(), the importance of pop-up blockers, and user experience considerations, demonstrating a holistic understanding.
Be ready to explain a real-world scenario where you would use it, and perhaps even write a quick code snippet on a whiteboard!
Wrapping It Up: Empowering Your ServiceNow Instances
The Glide Navigation API, primarily exposed through the g_navigation object, is a testament to ServiceNow’s commitment to providing robust client-side tooling. It transforms static forms and lists into dynamic, responsive interfaces that anticipate user needs and guide them effortlessly through complex workflows.
By mastering g_navigation.open(), g_navigation.openPopup(), and g_navigation.redirect(), you gain the power to craft truly exceptional user experiences, reduce friction, and make your ServiceNow instances more intuitive and efficient. So go forth, experiment, and make your users’ journeys through ServiceNow a whole lot smoother!