Skip to content
IT Canvass
ServiceNow Cheat Sheets · Lesson

GlideRecord cheat sheet

Quick answer

Bookmark this. Run any snippet in the editor below.

Key takeaways

  • Query
  • Iterate
  • CRUD

Bookmark this. Run any snippet in the editor below.

Query

var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.addQuery('priority', '<=', 2);
gr.orderByDesc('sys_created_on');
gr.setLimit(10);
gr.query();

Iterate

while (gr.next()) {
  gs.info(gr.number + ' ' + gr.getValue('short_description'));
}

CRUD

gr.initialize();
gr.setValue('short_description', 'New');
var id = gr.insert();
// gr.update();  gr.deleteRecord();

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 sorts newest first?

    • A. orderByDesc()
    • B. orderBy()
    • C. setLimit()
    Show answer

    A. orderByDesc()

    orderByDesc sorts descending.

  2. Which starts a brand new record?

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

    A. initialize()

    initialize() prepares a new record for insert.

Frequently asked questions

What does the term GlideRecord cheat sheet refer to in ServiceNow?

Bookmark this. Run any snippet in the editor below.
CallWhatsAppEnquire