Service Now Client Script Globals
Tags: servicenow, javascript, devops
Published: 2020-02-24 01:31:21

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.


<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org0e57e0d">Officially Documented Client APIs / Classes</a>
<ul>
<li><a href="#org5a969e9">Limited Availability</a></li>
</ul>
</li>
<li><a href="#org94e3724">Deprecated or Undocumented APIs/Classes</a>
<ul>
<li><a href="#org72ed592">Deprecated</a></li>
<li><a href="#org12cef0c">Undocumented</a></li>
</ul>
</li>
</ul>
</div>
</div>

<div id="outline-container-org0e57e0d" class="outline-2">
<h2 id="org0e57e0d">Officially Documented Client APIs / Classes</h2>
<div class="outline-text-2" id="text-org0e57e0d">
</div>
<div id="outline-container-orgac573e5" class="outline-4">
<h4 id="orgac573e5"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=GlideAgentWorkspaceAPI">CustomEvent</a></h4>
<div class="outline-text-4" id="text-orgac573e5">
<ul class="org-ul">
<li>Very underdocumented. Was previously available as &ldquo;Event&rdquo;</li>
<li>It&rsquo;s possible to write a hook for Any DOM event implementing <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event">Event</a> using this.</li>
<li>A usage example (with the old name) can be <a href="https://snprotips.com/undocumented-servicenow-apis#Event">found here</a></li>
</ul>
</div>
</div>
<div id="outline-container-org10ed892" class="outline-4">
<h4 id="org10ed892"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=DynamicTranslationClientAPI">DynamicTranslation</a></h4>
<div class="outline-text-4" id="text-org10ed892">
<ul class="org-ul">
<li>An active translator</li>
<li>Distinct from nowapi.g_i18n, which pulls pre-localized messages</li>
</ul>
</div>
</div>
<div id="outline-container-org4b4cfb9" class="outline-4">
<h4 id="org4b4cfb9"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideFormAPI">g_form</a></h4>
<div class="outline-text-4" id="text-org4b4cfb9">
<ul class="org-ul">
<li>Provides control of the main form, including fields. Very useful!</li>
<li>I believe there are a few undocumented methods, but I haven&rsquo;t doublechecked.</li>
</ul>
</div>
</div>
<div id="outline-container-org82d2107" class="outline-4">
<h4 id="org82d2107"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideNavigationV3API">g_navigation</a></h4>
<div class="outline-text-4" id="text-org82d2107">
<ul class="org-ul">
<li>Provides control of page navigation.</li>
</ul>
</div>
<ul class="org-ul">
<li><a id="orgd5fee1f"></a>There are several undocumented methods:<br />
<div class="outline-text-5" id="text-orgd5fee1f">
<ul class="org-ul">
<li>addUserHistoryEntry: Inserts history entries (for use with UI back button)</li>
<li>getURL: Gets the current page URL</li>
<li>openList: Opens a *_list.do page. Accepts a table and (optional) query parameter.</li>
<li>setPermalink: Adds a new favorite to the Megellan Navigator</li>
</ul>
</div>
</li>
</ul>
</div>
<div id="outline-container-orgb88835e" class="outline-4">
<h4 id="orgb88835e"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideUserAPI">g_user</a></h4>
<div class="outline-text-4" id="text-orgb88835e">
<ul class="org-ul">
<li>Provides information about the logged in user</li>
<li>This doesn&rsquo;t expose date/time settings (see g_user_date_format/g_user_date_time_format)</li>
</ul>
</div>
</div>
<div id="outline-container-orga6256a5" class="outline-4">
<h4 id="orga6256a5"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=GUIScriptsAPI">getUIScript / g_ui_scripts</a></h4>
<div class="outline-text-4" id="text-orga6256a5">
<ul class="org-ul">
<li>Provides access to UI Scripts.</li>
<li>Exposed as an object named g_ui_scripts in Service Portal/Mobile</li>
</ul>
</div>
</div>
<div id="outline-container-org5ad1b74" class="outline-4">
<h4 id="org5ad1b74"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideAjaxAPI">GlideAjax</a></h4>
<div class="outline-text-4" id="text-org5ad1b74">
<p>
Used to call ScriptIncludes remotely, but only if they inherit AbstractAjaxProcessor
</p>
</div>
</div>
<div id="outline-container-org9d8a856" class="outline-4">
<h4 id="org9d8a856"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=GlideFlowAPI">GlideFlow</a></h4>
<div class="outline-text-4" id="text-org9d8a856">
<p>
Used for working with Actions/Flows/Subflows
</p>
</div>
</div>
<div id="outline-container-orge24834e" class="outline-4">
<h4 id="orge24834e"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideModalClientSideV3API">GlideModal</a></h4>
<div class="outline-text-4" id="text-orge24834e">
<ul class="org-ul">
<li>Supercedes GlideDialogWindow</li>
<li>Need to revisit later to find any useful undocumented methods</li>
</ul>
</div>
</div>
<div id="outline-container-orgdd07a77" class="outline-4">
<h4 id="orgdd07a77"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideModalFormV3API">GlideModalForm</a></h4>
<div class="outline-text-4" id="text-orgdd07a77">
<ul class="org-ul">
<li>Supercedes GlideDialogForm</li>
<li>A specialized GlideModal for displaying record forms</li>
<li>Need to revisit later to find any useful undocumented methods</li>
</ul>
</div>
</div>
<div id="outline-container-org20fce2d" class="outline-4">
<h4 id="org20fce2d"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideRecordClientSideAPI">GlideRecord</a></h4>
<div class="outline-text-4" id="text-org20fce2d">
<p>
Used to query and modify records. Server-side usage is preferred for performance reasons
</p>
</div>
</div>
<div id="outline-container-org605f889" class="outline-4">
<h4 id="org605f889"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideURLV3API">GlideURL</a></h4>
<div class="outline-text-4" id="text-org605f889">
<ul class="org-ul">
<li>Convenience class for creating new URLs, as well as for examining the current URL.</li>
</ul>
</div>
<ul class="org-ul">
<li><a id="orgda952d1"></a>Undocumented methods:<br />
<div class="outline-text-5" id="text-orgda952d1">
<ul class="org-ul">
<li>addEncodedString: Processes an encoded string into parameters</li>
<li>addToken: Adds a authorization token to the URI</li>
<li>deleteParam: Deletes a parameter from the URI</li>
<li>getContextPath: Gets the base URI, not including parameters</li>
<li>getParam: Gets the value of the specified parameter</li>
<li>getParams: Gets an object representation of all parameters</li>
<li>getQueryString: Gets the parameter string, everything after the base URI</li>
</ul>
</div>
</li>
</ul>
</div>
<div id="outline-container-org08f02cc" class="outline-4">
<h4 id="org08f02cc"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=NotifyOnTaskClient">NotifyOnTaskClient</a></h4>
<div class="outline-text-4" id="text-org08f02cc">
<p>
Further VoIP integration, conference calls (needs to be enabled)
</p>
</div>
</div>
<div id="outline-container-orgf0d2fef" class="outline-4">
<h4 id="orgf0d2fef"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=guided_toursAPI">NOW.guided_tours.api</a></h4>
<div class="outline-text-4" id="text-orgf0d2fef">
<ul class="org-ul">
<li>Seems mostly for demos</li>
<li>There are other items under NOW worth looking into more</li>
</ul>
</div>
</div>
<div id="outline-container-orgd9fe207" class="outline-4">
<h4 id="orgd9fe207"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideDocumentV3API">nowapi.g_document</a></h4>
<div class="outline-text-4" id="text-orgd9fe207">
<ul class="org-ul">
<li>Documentation says this is accessible as g_document, but I can only get it with nowapi.g_document</li>
<li>There&rsquo;s an undocumented createElement method which exposes <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement">document.createElement</a></li>
</ul>
</div>
</div>
<div id="outline-container-org8c05e15" class="outline-4">
<h4 id="org8c05e15"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideGuidV3API">nowapi.g_guid</a></h4>
<div class="outline-text-4" id="text-org8c05e15">
<p>
Documentation says this is accessible as g_guid, but I can only get it with nowapi.g_document
</p>
</div>
</div>
<div id="outline-container-orgbdabf91" class="outline-4">
<h4 id="orgbdabf91"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_i18NV3API">nowapi.g_i18n</a></h4>
<div class="outline-text-4" id="text-orgbdabf91">
<p>
Localization tool. Replaces getMessage and GwtMessage
</p>
</div>
</div>
<div id="outline-container-orgb728937" class="outline-4">
<h4 id="orgb728937"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideNotificationV3">nowapi.g_notification</a></h4>
<div class="outline-text-4" id="text-orgb728937">
<ul class="org-ul">
<li>Claims to spawn a notification at the top of the screen, but seems to have no effect.</li>
<li>g_form.addErrorMessage/addWarningMessage/addInfoMessage seem to already do this.</li>
</ul>
</div>
</div>
<div id="outline-container-org1537691" class="outline-4">
<h4 id="org1537691"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_openFrameAPI">openFrameAPI</a></h4>
<div class="outline-text-4" id="text-org1537691">
<p>
An always-available overlay meant for use with VoIP/comms integration (needs to be enabled)
</p>
</div>
</div>
<div id="outline-container-org01adc8a" class="outline-4">
<h4 id="org01adc8a"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_Notify2WebRTCClient">SNC.Notify.Client</a></h4>
<div class="outline-text-4" id="text-org01adc8a">
<p>
VoIP integration (needs to be enabled)
</p>
</div>
</div>
<div id="outline-container-org5dc87fa" class="outline-4">
<h4 id="org5dc87fa"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_StopWatchAPI">StopWatch</a></h4>
<div class="outline-text-4" id="text-org5dc87fa">
<p>
Developer tool, used to measure load times
</p>
</div>
</div>
<div id="outline-container-org5a969e9" class="outline-3">
<h3 id="org5a969e9">Limited Availability</h3>
<div class="outline-text-3" id="text-org5a969e9">
</div>
<div id="outline-container-org14f3e01" class="outline-4">
<h4 id="org14f3e01">Classic UI Only</h4>
<div class="outline-text-4" id="text-org14f3e01">
</div>
<ul class="org-ul">
<li><a id="orgf22edf3"></a><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_ScriptLoaderAPI">ScriptLoader</a><br />
<div class="outline-text-5" id="text-orgf22edf3">
<ul class="org-ul">
<li>Async Script Includes loader.</li>
<li>Unavailable outside form UIs (no Agent Workspace nor Service Portal).</li>
<li><a href="https://community.servicenow.com/community?id=community_question&amp;sys_id=98004feddb58dbc01dcaf3231f9619eb">Useful for injecting scripts into a page for later use</a>
<ul class="org-ul">
<li>Example: within UI Scripts</li>
</ul></li>
<li>It seems implied that this is going to be deprecated at some point?</li>
</ul>
</div>
</li>
</ul>
</div>
<div id="outline-container-org39479c2" class="outline-4">
<h4 id="org39479c2">Agent Workspace Only</h4>
<div class="outline-text-4" id="text-org39479c2">
</div>
<ul class="org-ul">
<li><a id="org121f1a2"></a><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=GlideAgentWorkspaceAPI">g_aw</a><br />
<div class="outline-text-5" id="text-org121f1a2">
<p>
Provides helpers specific to the agent workspace (need to investigate further)
</p>
</div>
</li>
</ul>
</div>
<div id="outline-container-org22c7c48" class="outline-4">
<h4 id="org22c7c48">Service Portal Widgets</h4>
<div class="outline-text-4" id="text-org22c7c48">
</div>
<ul class="org-ul">
<li><a id="org644abf4"></a><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=spAriaUtil-API">spAriaUtil</a><br />
<div class="outline-text-5" id="text-org644abf4">
<p>
Used to send live text updates
</p>
</div>
</li>
<li><a id="orgaafe794"></a><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=spContextManagerAPI">spContextManager</a><br />
<div class="outline-text-5" id="text-orgaafe794">
<p>
Used to pass data to the main Service Portal page from within a widget
</p>
</div>
</li>
<li><a id="org91734e1"></a><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=SPModal-API">spModal</a><br />
<div class="outline-text-5" id="text-org91734e1">
<p>
Summons a modal within a widget
</p>
</div>
</li>
<li><a id="org4aad8af"></a><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=spUtilAPI">spUtil</a><br />
<div class="outline-text-5" id="text-org4aad8af">
<p>
A general utility class for widgets (logging, formatting, refreshing, etc.)
</p>
</div>
</li>
</ul>
</div>
<div id="outline-container-orgad0f8e8" class="outline-4">
<h4 id="orgad0f8e8">Only Available in Specific Contexts</h4>
<div class="outline-text-4" id="text-orgad0f8e8">
</div>
<ul class="org-ul">
<li><a id="org003fdc1"></a><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideMenuAPI">g_item/g_menu</a><br />
<div class="outline-text-5" id="text-org003fdc1">
<ul class="org-ul">
<li>Used within onShow scripts for UI Context Menus.
<ul class="org-ul">
<li>g_menu = the new context menu element</li>
<li>g_item = context menu items within g_menu</li>
</ul></li>
</ul>
</div>
</li>
<li><a id="org04bc71d"></a><a href="https://servicenowgems.com/2016/10/10/understanding-scratchpad-g_scratchpad/">g_scratchpad</a><br />
<div class="outline-text-5" id="text-org04bc71d">
<ul class="org-ul">
<li>An object available in onDisplay business rules used for passing commonly requested information pre-emptively.
<ul class="org-ul">
<li>This can only be written from the server at display-time.</li>
</ul></li>
<li>Once the page is served, g_scratchpad becomes an object on the client which may be freely accessed.</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-org94e3724" class="outline-2">
<h2 id="org94e3724">Deprecated or Undocumented APIs/Classes</h2>
<div class="outline-text-2" id="text-org94e3724">
</div>
<div id="outline-container-org72ed592" class="outline-3">
<h3 id="org72ed592">Deprecated</h3>
<div class="outline-text-3" id="text-org72ed592">
</div>
<div id="outline-container-orgd3fbfa5" class="outline-4">
<h4 id="orgd3fbfa5"><a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideDialogWindowAPI">GlideDialogWindow</a></h4>
<div class="outline-text-4" id="text-orgd3fbfa5">
<p>
Deprecated in favor of GlideModal
</p>
</div>
</div>
<div id="outline-container-orga112f61" class="outline-4">
<h4 id="orga112f61"><a href="https://snprotips.com/undocumented-servicenow-apis#GlideDialogForm">GlideDialogForm</a></h4>
<div class="outline-text-4" id="text-orga112f61">
<p>
Undocumented, yet still somehow deprecated (<a href="https://developer.servicenow.com/app.do#!/api_doc?v=newyork&amp;id=c_GlideModalClientSideV3API">see here</a>) in favor of GlideModalForm
</p>
</div>
</div>
</div>
<div id="outline-container-org12cef0c" class="outline-3">
<h3 id="org12cef0c">Undocumented</h3>
<div class="outline-text-3" id="text-org12cef0c">
</div>
<div id="outline-container-org3329fdd" class="outline-4">
<h4 id="org3329fdd"><a href="https://community.servicenow.com/community?id=community_blog&amp;sys_id=01ccee25dbd0dbc01dcaf3231f9619dc">g_tabs2Sections</a></h4>
<div class="outline-text-4" id="text-org3329fdd">
<p>
API Used within forms for controlling section tabs in a given form
</p>
</div>
</div>
<div id="outline-container-org27cc7d9" class="outline-4">
<h4 id="org27cc7d9">g_tabs2List</h4>
<div class="outline-text-4" id="text-org27cc7d9">
<ul class="org-ul">
<li>API Used within forms for controlling the related list tabs.</li>
<li>Essentially identical in use to g_tabs2Sections</li>
</ul>
</div>
</div>
<div id="outline-container-org5a2fb90" class="outline-4">
<h4 id="org5a2fb90"><a href="https://snprotips.com/undocumented-servicenow-apis#getDateFromFormat">getDateFromFormat</a></h4>
<div class="outline-text-4" id="text-org5a2fb90">
<p>
Parses a GlideDate from a string. Useful for field validation
</p>
</div>
</div>
<div id="outline-container-org23572cd" class="outline-4">
<h4 id="org23572cd"><a href="https://community.servicenow.com/community?id=community_question&amp;sys_id=9fded84cdb355f004837f3231f96195e">getMessage</a></h4>
<div class="outline-text-4" id="text-org23572cd">
<ul class="org-ul">
<li>Replaced GwtMessage, works on Service Portal. Does not support string insertion</li>
<li>Superceded by nowapi.g_i18n, which is fully featured.</li>
</ul>
</div>
</div>
<div id="outline-container-orgc0ab8c7" class="outline-4">
<h4 id="orgc0ab8c7">GlideUI</h4>
<div class="outline-text-4" id="text-orgc0ab8c7">
<ul class="org-ul">
<li>Provides the parent UI the form lives in, where messages are stored. Can be accessed via GlideUI.get()</li>
<li>Messages triggered via g_form.add*Message can be manipulated via the messages property
<ul class="org-ul">
<li>All messages types can be conveniently cleared out using the clearOutputMessages method</li>
</ul></li>
</ul>
</div>
</div>
<div id="outline-container-org07bf59f" class="outline-4">
<h4 id="org07bf59f"><a href="https://community.servicenow.com/community?id=community_question&amp;sys_id=69eec3a1dbdcdbc01dcaf3231f9619c1">GwtContextMenu</a></h4>
<div class="outline-text-4" id="text-org07bf59f">
<p>
Allows invoking your own context menus (submenus, for example)
</p>
</div>
</div>
<div id="outline-container-orgf34ef26" class="outline-4">
<h4 id="orgf34ef26"><a href="https://community.servicenow.com/community?id=community_question&amp;sys_id=e2715f2ddbdcdbc01dcaf3231f961978">GwtMessage</a></h4>
<div class="outline-text-4" id="text-orgf34ef26">
<p>
Legacy equivalent localization getter. Not extant on the Service Portal
</p>
</div>
</div>
<div id="outline-container-org9d4fb3e" class="outline-4">
<h4 id="org9d4fb3e"><a href="https://snprotips.com/undocumented-servicenow-apis#g-user-date-format">g_user_date_format</a></h4>
<div class="outline-text-4" id="text-org9d4fb3e">
<p>
Exposes the client date format
</p>
</div>
</div>
<div id="outline-container-org4b2a81b" class="outline-4">
<h4 id="org4b2a81b"><a href="https://snprotips.com/undocumented-servicenow-apis#g-user-date-time-format">g_user_date_time_format</a></h4>
<div class="outline-text-4" id="text-org4b2a81b">
<p>
Exposes the client time format
</p>
</div>
</div>
<div id="outline-container-org0863270" class="outline-4">
<h4 id="org0863270">NOW.g_clipboard</h4>
<div class="outline-text-4" id="text-org0863270">
<p>
Has a single method: copyToClipboard. Pretty self-explanatory (verified working in Chrome)
</p>
</div>
</div>
<div id="outline-container-org5eff3cf" class="outline-4">
<h4 id="org5eff3cf">Table</h4>
<div class="outline-text-4" id="text-org5eff3cf">
<ul class="org-ul">
<li>This lets you query a Table by name. Seems to be used mostly in the Field Map UI</li>
<li>See the &ldquo;Hide Date Format&rdquo; Client script for a real example.</li>
</ul>
</div>
</div>
</div>
</div>
<h2>JS Globals List (for linting)</h2>
```javascript
[
  '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'
]
```