ServiceNow Snippets · LessonBy Sneha I, ServiceNow Trainer, 8 yrs · Published · Updated · current release · reference
ServiceNow GlideRecord snippets
Short, runnable GlideRecord snippets to copy.
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'));Try it YourselfJavaScript
▸ Press Run to execute.
Runs in a sandbox in your browser. Mock gs and GlideRecord and sample data are provided.
Quick check
+0 XPStreak ×0
Question 1 of 2
Which deletes all matching records at once?
Practise this on your own free instance.