Skip to content
Rise Gen
Scripting8 min read

ServiceNow Scripting Tutorial: GlideRecord Basics

A hands-on ServiceNow scripting tutorial covering GlideRecord queries, inserts and updates with copy-paste examples.

By the Rise Gen Technologies trainer team

What is GlideRecord?

GlideRecord is the server-side API used to query and modify records in any ServiceNow table. It is the single most important API in ServiceNow scripting.

Querying records

This query returns all active priority-1 incidents.

var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.addQuery('priority', 1);
gr.query();
while (gr.next()) {
  gs.info(gr.getValue('number') + ' - ' + gr.getValue('short_description'));
}

Inserting and updating

Use initialize() and insert() to create records, and update() after changing fields.

var inc = new GlideRecord('incident');
inc.initialize();
inc.setValue('short_description', 'Email not syncing');
inc.setValue('urgency', 2);
var sysId = inc.insert();

Best practices

Always use setLimit() when you need one record, prefer GlideAggregate for counts, and avoid queries inside loops.

More scripting guides

START YOUR JOURNEY TODAY

Start your ServiceNow career this month.

Book a free demo class with a working ServiceNow Architect. New online and classroom batches in Hyderabad start every two weeks.

CallWhatsAppEmailVideo Demo