Skip to content
IT Canvass
ServiceNow Examples · Lesson

GlideRecord examples

Quick answer

These are the GlideRecord patterns you reach for daily. Run the example below, then adapt it, the sandbox ships with sample incident, problem and sys_user data.

Key takeaways

  • Query and loop
  • Get a single record
  • Update matching records

These are the GlideRecord patterns you reach for daily. Run the example below, then adapt it, the sandbox ships with sample incident, problem and sys_user data.

Query and loop

var gr = new GlideRecord('incident');
gr.addActiveQuery();
gr.query();
while (gr.next()) {
  gs.info(gr.number + ' - ' + gr.short_description);
}

Get a single record

var gr = new GlideRecord('incident');
if (gr.get('number', 'INC0010023')) {
  gs.info('Found: ' + gr.short_description);
}

Update matching records

var gr = new GlideRecord('incident');
gr.addQuery('priority', 1);
gr.query();
while (gr.next()) {
  gr.setValue('urgency', 1);
  gr.update();
}

Want to learn this properly?

Our live, instructor-led ServiceNow Training covers this hands-on, with real projects and a certification path.

Check your understanding

  1. Which method returns a single record by field value?

    • A. get()
    • B. next()
    • C. query()
    Show answer

    A. get()

    get() fetches one matching record.

  2. What must you call before next() iterates?

    • A. query()
    • B. update()
    • C. initialize()
    Show answer

    A. query()

    query() runs the query so next() can iterate.

Frequently asked questions

What does the term GlideRecord examples refer to in ServiceNow?

These are the GlideRecord patterns you reach for daily. Run the example below, then adapt it, the sandbox ships with sample incident, problem and sys_user data.
CallWhatsAppEnquire