DEV Community

Chris
Chris

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

CustomEvent

  • 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

DynamicTranslation

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

g_form

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

g_navigation

  • 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 *_list.do page. Accepts a table and (optional) query parameter.
    • setPermalink: Adds a new favorite to the Megellan Navigator

g_user

  • 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

GlideAjax

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

GlideFlow

Used for working with Actions/Flows/Subflows

GlideModal

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

GlideModalForm

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

GlideRecord

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

GlideURL

  • 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

NotifyOnTaskClient

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

NOW.guided_tours.api

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

nowapi.g_document

  • 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

nowapi.g_guid

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

nowapi.g_i18n

Localization tool. Replaces getMessage and GwtMessage

nowapi.g_notification

  • 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.

openFrameAPI

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

SNC.Notify.Client

VoIP integration (needs to be enabled)

StopWatch

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

GlideDialogWindow

Deprecated in favor of GlideModal

GlideDialogForm

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


Undocumented

g_tabs2Sections

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

g_tabs2List

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

getDateFromFormat

Parses a GlideDate from a string. Useful for field validation

getMessage

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

GlideUI

  • 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

GwtContextMenu

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

GwtMessage

Legacy equivalent localization getter. Not extant on the Service Portal

g_user_date_format

Exposes the client date format

g_user_date_time_format

Exposes the client time format

NOW.g_clipboard

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

Table

  • 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)

[
  'CustomEvent',
  'DynamicTranslation',
  'GlideAjax',
  'GlideDialogForm',
  'GlideDialogWindow',
  'GlideFlow',
  'GlideModalForm',
  'GlideRecord',
  'GlideUI',
  'GwtContextMenu',
  'GwtMessage',
  'NOW',
  'NotifyOnTaskClient',
  'SNC',
  'ScriptLoader',
  'Table',
  'g_aw',
  'g_form',
  'g_item',
  'g_list',
  'g_menu',
  'g_navigation',
  'g_scratchpad',
  'g_service_catalog',
  'g_tabs2List',
  'g_tabs2Sections',
  'g_ui_scripts',
  'g_user',
  'g_user_date_format',
  'g_user_date_time_format',
  'getDateFromFormat',
  'getMessage',
  'getNavWindow',
  'getUIScript',
  'nowapi',
  'openFrameAPI',
  'spAriaUtil',
  'spContextManager',
  'spModal',
  'spUtil'
]

Top comments (0)