GROW

code

Client navigation

This issue is found automatically by CODA.
Time to fix: 01h 45min

What is the g_navigation?

The g_navigation is a GlideNavigation global object in ServiceNow that allows you to interact with the navigation component, which provides a way for users to navigate through different areas of the ServiceNow instance. This hook exposes a number of methods that you can use in your scripts to execute and control different behaviors.

Why is this an issue?

Using a method that is not part of the ServiceNow API, such as DOM manipulation like window.open, can negatively impact your instance in a few ways:

  • Consistency: A random JavaScript method will not be as consistent as the methods provided by ServiceNow. The official methods are designed to work with the ServiceNow platform, and they will be updated as the platform is updated. Using a random JavaScript method could lead to your code breaking if the platform changes.

  • Security: The official methods are more secure than random JavaScript methods. The official methods have been designed with security in mind, and they are less likely to be exploited by attackers. Using a random JavaScript method could expose your instance to security vulnerabilities.

How do I fix it?

To fix this issue and make your code more reliable in the ServiceNow instance, replace the script appointed as not g_navigation with one of those provided in the ServiceNow GlideNavigation. Some examples of these methods include:

  • .open: This method redirects the user to a different URL.
1
g_navigation.open("incident_list.do?sysparm_query=active=true");
  • .openPopup: This method opens a new window to the specified URL.
1
2
3
4
5
6
g_navigation.openPopup(
  "incident_list.do?sysparm_query=active=true",
  "Active Incidents",
  "resizable,scrollbars,status",
  true,
);
  • .openRecord: This method navigates to a record specified by its sys_id.
1
g_navigation.openRecord("incident", "4e49c0e81bf198101363ff37dc4bcb8a");
  • .refreshNavigator: This method refreshes the navigation frame.
1
g_navigation.refreshNavigator();