IT CanvassTalk to an advisor
ServiceNow Examples · LessonBy , ServiceNow Architect · Published · current release · reference

GlideRecord examples

Copy-paste GlideRecord patterns for the most common queries.

Quick answer

These are the GlideRecord patterns you reach for daily. Run the example below, then adapt it, the sandbox ships with sample incident, problem and sys_user data.

Key takeaways
  • Query and loop
  • Get a single record
  • Update matching records

These are the GlideRecord patterns you reach for daily. Run the example below, then adapt it, the sandbox ships with sample incident, problem and sys_user data.

Query and loop

var gr = new GlideRecord('incident');
gr.addActiveQuery();
gr.query();
while (gr.next()) {
  gs.info(gr.number + ' - ' + gr.short_description);
}

Get a single record

var gr = new GlideRecord('incident');
if (gr.get('number', 'INC0010023')) {
  gs.info('Found: ' + gr.short_description);
}

Update matching records

var gr = new GlideRecord('incident');
gr.addQuery('priority', 1);
gr.query();
while (gr.next()) {
  gr.setValue('urgency', 1);
  gr.update();
}
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 method returns a single record by field value?

Frequently asked questions

What does the term GlideRecord examples refer to in ServiceNow?
These are the GlideRecord patterns you reach for daily. Run the example below, then adapt it, the sandbox ships with sample incident, problem and sys_user data.
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