DEV Community


Posted on

Service Now Client Script Globals

I'm making a linter for Service Now Client Scripts. Seems easy, right? Just find the list of common global variables and... oh, that doesn't exist.

Long story short, I just spent all day combing through raw scripts and cross-referencing every single Class reference I could find! I wound up with a shiny new reference document, which can be found immediately below. Those looking for the titular globals list should skip directly to the bottom for a raw copy.

Table of Contents

Officially Documented Client APIs / Classes


  • Very underdocumented. Was previously available as “Event”
  • It’s possible to write a hook for Any DOM event implementing Event using this.
  • A usage example (with the old name) can be found here


  • An active translator
  • Distinct from nowapi.g_i18n, which pulls pre-localized messages


  • Provides control of the main form, including fields. Very useful!
  • I believe there are a few undocumented methods, but I haven’t doublechecked.


  • Provides control of page navigation.
  • There are several undocumented methods:
    • addUserHistoryEntry: Inserts history entries (for use with UI back button)
    • getURL: Gets the current page URL
    • openList: Opens a * page. Accepts a table and (optional) query parameter.
    • setPermalink: Adds a new favorite to the Megellan Navigator


  • Provides information about the logged in user
  • This doesn’t expose date/time settings (see g_user_date_format/g_user_date_time_format)

getUIScript / g_ui_scripts

  • Provides access to UI Scripts.
  • Exposed as an object named g_ui_scripts in Service Portal/Mobile


Used to call ScriptIncludes remotely, but only if they inherit AbstractAjaxProcessor


Used for working with Actions/Flows/Subflows


  • Supercedes GlideDialogWindow
  • Need to revisit later to find any useful undocumented methods


  • Supercedes GlideDialogForm
  • A specialized GlideModal for displaying record forms
  • Need to revisit later to find any useful undocumented methods


Used to query and modify records. Server-side usage is preferred for performance reasons


  • Convenience class for creating new URLs, as well as for examining the current URL.
  • Undocumented methods:
    • addEncodedString: Processes an encoded string into parameters
    • addToken: Adds a authorization token to the URI
    • deleteParam: Deletes a parameter from the URI
    • getContextPath: Gets the base URI, not including parameters
    • getParam: Gets the value of the specified parameter
    • getParams: Gets an object representation of all parameters
    • getQueryString: Gets the parameter string, everything after the base URI


Further VoIP integration, conference calls (needs to be enabled)


  • Seems mostly for demos
  • There are other items under NOW worth looking into more


  • Documentation says this is accessible as g_document, but I can only get it with nowapi.g_document
  • There’s an undocumented createElement method which exposes document.createElement


Documentation says this is accessible as g_guid, but I can only get it with nowapi.g_document


Localization tool. Replaces getMessage and GwtMessage


  • Claims to spawn a notification at the top of the screen, but seems to have no effect.
  • g_form.addErrorMessage/addWarningMessage/addInfoMessage seem to already do this.


An always-available overlay meant for use with VoIP/comms integration (needs to be enabled)


VoIP integration (needs to be enabled)


Developer tool, used to measure load times

Limited Availability

Classic UI Only

Agent Workspace Only

  • g_aw

    Provides helpers specific to the agent workspace (need to investigate further)

Service Portal Widgets

  • spAriaUtil

    Used to send live text updates

  • spContextManager

    Used to pass data to the main Service Portal page from within a widget

  • spModal

    Summons a modal within a widget

  • spUtil

    A general utility class for widgets (logging, formatting, refreshing, etc.)

Only Available in Specific Contexts

  • g_item/g_menu
    • Used within onShow scripts for UI Context Menus.
      • g_menu = the new context menu element
      • g_item = context menu items within g_menu
  • g_scratchpad
    • An object available in onDisplay business rules used for passing commonly requested information pre-emptively.
      • This can only be written from the server at display-time.
    • Once the page is served, g_scratchpad becomes an object on the client which may be freely accessed.

Deprecated or Undocumented APIs/Classes



Deprecated in favor of GlideModal


Undocumented, yet still somehow deprecated (see here) in favor of GlideModalForm



API Used within forms for controlling section tabs in a given form


  • API Used within forms for controlling the related list tabs.
  • Essentially identical in use to g_tabs2Sections


Parses a GlideDate from a string. Useful for field validation


  • Replaced GwtMessage, works on Service Portal. Does not support string insertion
  • Superceded by nowapi.g_i18n, which is fully featured.


  • Provides the parent UI the form lives in, where messages are stored. Can be accessed via GlideUI.get()
  • Messages triggered via g_form.add*Message can be manipulated via the messages property
    • All messages types can be conveniently cleared out using the clearOutputMessages method


Allows invoking your own context menus (submenus, for example)


Legacy equivalent localization getter. Not extant on the Service Portal


Exposes the client date format


Exposes the client time format


Has a single method: copyToClipboard. Pretty self-explanatory (verified working in Chrome)


  • This lets you query a Table by name. Seems to be used mostly in the Field Map UI
  • See the “Hide Date Format” Client script for a real example.

JS Globals List (for linting)


Top comments (0)