Servicenow Gliderecord Cheat Sheet



GlideRecord & GlideAggregate Cheat Sheet. ServiceNow UI Developer cheat sheet. URL Purpose /stats.do: Quick stats /cache.do: Clear your instance cache: 1 file 0 forks 0 comments 0 stars nancystodd / debuggingcheatsheet.md. Created Oct 25, 2019. ServiceNow provides JavaScript APIs for use within scripts running on the ServiceNow platform to deliver common functionality. This reference lists available classes and methods along with parameters, descriptions, and examples to make extending the ServiceNow platform easier. Please note: The APIs below are intended for scoped applications and may behave differently in the global scope.

The most common and fundamental scripting used in ServiceNow is GlideRecord. Alter and reuse these scripts found in this post for your ServiceNow implementation.

Sheet

Important Note: Always run GlideRecord statements in a development instance first and make sure they work correctly before using in production!

Query

WHILE LOOP

This will return multiple records, because a while statement is used to cycle through the query results.

IF STATEMENT

This will return one record, because a if statement is used to cycle through the query results. This is good if you just want to find one record, however the query would have returned seven items, which isn't completely efficent.

Gliderecord

SET LIMIT

The setLimit statement helps performance, because only one record is returned with the query.

ENCODED QUERY

Using an encoded query is often easier than multiple addQuery lines. You can also use Copy Query to help figure out your encoded query content which is helpful.

GET

it will return one record, because a get statement is used.

OR QUERY

Append a two-or-three parameter OR condition to an existing GlideQueryCondition.

I prefer to use an encoded query instead of this, but there are situations where this is easier.

INSERT

UPDATE

UPDATE

If you are doing an update statement in your script, it is good to be extra careful. Comment out your update statement and add a log statement to check the script for accuracy before actually using it.

setWorkflow(false) and autoSysFields(false)

Sheet

When you are mass updating records, sometimes you don't want to run the business rules/workflow on every record you updated or have your name and the last updated time be when you updated it. Here is an example on how to avoid this:

DELETE

If you are doing an delete statement in your script, it is good to be extra careful. Comment out your delete statement and add a log statement to check the script for accuracy before actually using it.

Servicenow Gliderecord Cheat Sheet Pdf

You can use similar GildeRecord scripts on the client side, except you should enclose them in a GlideAjax Query

Gliderecord Sort

In the example below, it uses a Script Include and Client Script to set the Department field on a form based on the Requested For user.

Script Include

Client Script (ON LOAD)

CLIENT SCRIPT (ON CHANGE)