IT CanvassTalk to an advisor
ServiceNow Cheat Sheets · LessonBy , ServiceNow Trainer, 9 yrs · Published · Updated · current release · reference

ServiceNow GlideRecord cheat sheet

Every GlideRecord pattern on one page.

Quick answer

Bookmark this. Run any snippet in the editor below.

Key takeaways
  • Query
  • Iterate
  • CRUD

Bookmark this. Run any snippet in the editor below.

Query

var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.addQuery('priority', '<=', 2);
gr.orderByDesc('sys_created_on');
gr.setLimit(10);
gr.query();

Iterate

while (gr.next()) {
  gs.info(gr.number + ' ' + gr.getValue('short_description'));
}

CRUD

gr.initialize();
gr.setValue('short_description', 'New');
var id = gr.insert();
// gr.update();  gr.deleteRecord();
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 sorts newest first?
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