Skip to content
IT Canvass
ServiceNow Snippets · Lesson

GlideRecord snippets

Quick answer

Small, focused snippets. Run and tweak the one below.

Key takeaways

  • Delete matching records
  • Count without looping

Small, focused snippets. Run and tweak the one below.

Delete matching records

var gr = new GlideRecord('incident');
gr.addQuery('state', 7); // closed
gr.query();
// gr.deleteMultiple();

Count without looping

var ga = new GlideAggregate('incident');
ga.addAggregate('COUNT');
ga.query();
ga.next();
gs.info(ga.getAggregate('COUNT'));

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 deletes all matching records at once?

    • A. deleteMultiple()
    • B. deleteRecord()
    • C. next()
    Show answer

    A. deleteMultiple()

    deleteMultiple removes the whole result set.

  2. Which class counts without a loop?

    • A. GlideAggregate
    • B. GlideForm
    • C. GlideAjax
    Show answer

    A. GlideAggregate

    GlideAggregate aggregates in the database.

Frequently asked questions

What does the term GlideRecord snippets refer to in ServiceNow?

Small, focused snippets. Run and tweak the one below.
CallWhatsAppEnquire