GlideRecord reads and writes records on the server. Build the query, run it, then loop over the results. It ignores ACLs, so use GlideRecordSecure when the data goes back to a user.
Returns true when there is at least one more record, without moving to it.
var gr = newGlideRecord('sys_user_group');
gr.addQuery('name', 'Service Desk');
gr.setLimit(1);
gr.query();
if (gr.hasNext()) {
gs.info('Group exists');
}
initialize() prepares a new record with default values; insert() saves it and returns its sys_id.
var inc = newGlideRecord('incident');
inc.initialize();
inc.setValue('short_description', 'Printer on floor 3 is offline');
inc.setValue('caller_id', gs.getUserID());
var incidentId = inc.insert();
Without initialize() (or newRecord()), field defaults are not applied.
Skips business rules, notifications, workflows and audit for the next update.
var inc = newGlideRecord('incident');
if (inc.get(incidentId)) {
inc.setWorkflow(false); // data fix: skip notifications on purpose
inc.setValue('u_migrated', true);
inc.update();
}
Use it only when skipping all of that is intended, such as data fixes.
Updates the record without changing Updated, Updated by and the update count.
var inc = newGlideRecord('incident');
if (inc.get(incidentId)) {
inc.autoSysFields(false); // data fix: keep the original updated date
inc.setValue('u_migrated', true);
inc.update();
}
var inc = newGlideRecord('incident');
inc.addActiveQuery();
inc.query();
var count = inc.getRowCount();
It loads every matching record just to count them. Use GlideAggregate with COUNT instead.
GlideAggregate Server
GlideAggregate runs COUNT, SUM, MIN, MAX and AVG in the database, so you do not load records just to count them. It extends GlideRecord, so addQuery() and friends work the same way.
Returns the time between two date-times as a GlideDuration.
var opened = newGlideDateTime(current.getValue('opened_at'));
var duration = GlideDateTime.subtract(opened, newGlideDateTime());
gs.info('Open for ' + duration.getDisplayValue());
Milliseconds since 1 January 1970 (UTC). Handy for quick arithmetic.
var start = newGlideDateTime(current.getValue('opened_at'));
var hours = (newGlideDateTime().getNumericValue() - start.getNumericValue()) / 3600000;
Business rules Server
Business rules run on the server when a record is displayed, inserted, updated, deleted or queried. current is the record being saved; previous is how it looked before the update.
Before: change current, it is saved anyway. After: update other records. Async: slow work in the background. Display: send data to the form with g_scratchpad.
(functionexecuteRule(current, previous) {
// Before rule: no update() needed, the change is saved with the recordif (current.getValue('priority') == '1') {
current.setValue('u_major_incident', true);
}
})(current, previous);
Cancels the insert, update or delete. Use it in a before rule, with a message.
(functionexecuteRule(current, previous) {
if (gs.nil(current.getValue('close_notes'))) {
gs.addErrorMessage('Add close notes before resolving.');
current.setAbortAction(true);
}
})(current, previous);
In after and async rules the record is already saved, so aborting does nothing.
var ga = newGlideAjax('UserUtils');
ga.addParam('sysparm_name', 'getManager');
ga.getXMLWait();
var answer = ga.getAnswer();
It freezes the browser and is not supported in Service Portal. Use getXMLAnswer() with a callback.
g_form Client
g_form controls the form in client scripts, UI policies and client UI actions: read and set fields, show messages, and make fields mandatory, read-only or hidden.
The record's sys_id, its table, and whether it has been saved yet.
functiononLoad() {
if (g_form.isNewRecord()) {
g_form.setValue('contact_type', 'self-service');
}
}
Client scripts, g_user & g_scratchpad Client
Client scripts run in the browser. These are the four templates, plus g_user (the logged-in user) and g_scratchpad (data sent from a display business rule).
Glide is the set of JavaScript APIs ServiceNow scripts use: GlideRecord and GlideAggregate to read and write data, GlideSystem (gs) for users, properties, logging and events, GlideDateTime for dates, and in the browser g_form, g_user and GlideAjax.
Which methods work in scoped applications?
All methods on this sheet work in scoped apps unless the note says otherwise. The main exceptions are gs.log() and gs.print(), which only exist in global scope; use gs.info() and friends instead.
Are the examples tested?
Every example is run through the NowUtils Script Checker before it is published: it has to parse, work in ES5 mode for global scripts, and raise no high or medium findings. Examples marked Avoid show a common mistake and are caught by the checker. Last reviewed October 2026.
Where is the official ServiceNow API reference?
The full reference is in the ServiceNow developer documentation (API reference). This sheet is a quick, searchable shortcut to the methods developers use every day, with the gotchas that trip people up.