Snippets

Quickly discover relevant code snippets for ServiceNow development. Copy, paste, adapt.

Promisified GlideAjax

ServiceNowJavaScript

When client scripts rely on multiple GlideAjax calls, callback nesting can quickly become hard to read and maintain. A small Promise wrapper gives you cleaner flow, …

Every ServiceNow instance has an OOB page for codesearch: …

Server URL is stored in following property. gs.getProperty('glide.servlet.uri') Note 1: This property does not exists in the sys_properties table, but hard coded in …

Auto-login to an instance with URL parameters

ServiceNowRelease: OrlandoRelease: New York

There is a possibility to login to the instance via the URL. You just pass you login name and password via URL paremeters like follows: …

Not an easy to find functionality is hidden in this UI macros. It is being loaded on every form and renders context menu: context_form_header

Working with g_list

Code snippetServiceNow

Variable selectedSysIds will consist of sys_id`s of selected records. To be used from a UI Action (List). var selectedSysIds = g_list.getChecked();

Manipulate URL from client script

Code snippetServiceNow

Useful snippets for working with URL from a lient script Redirect to a page with a form for creating a new record var query = [ "active=true", …

Encoded query

Code snippetServiceNow

Most of the times its much easier to work with encoded query instead of builing a query with GlideRecord API: var query = "category=Hardware^priority=1"; var gr …

Using GSLog

Code snippetServiceNow

GSlog is the best way to output log infos from ServiceNow server scripts. Consider this snippet to get started. var logger = new global.GSLog('','My script'); …

Setup autocomplete for a reference field

AttributesServiceNowRelease: Orlando

Another tiny guide

Admins getting security constraints even though ACL has Admin override checked

Copy attachments from inbound action

SnippetServiceNowRelease: Orlando

From email to any record

Clone any record

Clone any record

Code snippetServiceNowRelease: Orlando

Get all fields of a source record and clone into a new one

Redirect from record producer

Code snippetServiceNowRelease: New York

How to redirect to another portal from record producer

Get a GlideRecord with a single line code

Get a GlideRecord with a single line code

Code snippetServiceNowRelease: Orlando

A simple code snippet for getting a GlideRecord