NowSpectrum
Issue #2

Hey {{first_name | there}},

Quick one this week — a single swap that makes your scripts noticeably faster.

💡 This week's tip: Replace your GlideRecord count loops.

If you've ever written something like this:

✕ The Slow Way
var count = 0;
var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true');
gr.query();

while (gr.next()) {
    count++;
}

You're loading every matching record into application server memory just to count them. On a busy instance with tens of thousands of incidents — that's slow, expensive, and completely unnecessary.

The fix — GlideAggregate:

✓ The Fast Way
var ga = new GlideAggregate('incident');
ga.addEncodedQuery('active=true');
ga.addAggregate('COUNT');
ga.query();

if (ga.next()) {
    var count = ga.getAggregate('COUNT');
}

GlideAggregate pushes the COUNT directly to the database. One query, one number returned. Zero records loaded into memory.

The rule: If you're writing a GlideRecord loop just to count, replace it immediately.

GlideAggregate also handles SUM, AVG, MIN, MAX, and GROUP BY — so you can get grouped counts by assignment group, category, or any other field without touching a single record.

📚 From the blog this week

→ GlideAggregate: Count, Sum, and Group Records Without Loading Them All

Full reference with GROUP BY, HAVING clause, and real examples.

→ GlideRecord Performance Tips

The top anti-patterns that slow ServiceNow instances — and the fixes.

🚀 This week on NowSpectrum

The site now has full consulting and talent services alongside the knowledge products. If your company needs a ServiceNow developer or admin — contract or permanent — or if you're looking for your next role, check out:

Keep Reading