IT CanvassTalk to an advisor
ServiceNow Snippets · LessonBy , 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.
Set up your free instance →
Already working on ServiceNow and stuck on a live ticket?Get an expert ServiceNow developer on screen-share to finish your daily tasks with you. Deliver on time, protect your reputation and your job. Monthly support only, no task-wise plans.Task assigned · no idea where to startStill stuck · your job on the lineExpert joins your screenDelivered on timeExplore On Job Support