ServiceNow GlideSystem (gs) cheat sheet
The gs object is available in every server script: logging, the current user, properties, messages, events and date helpers.
Server12 methods · examples checked with the Script Checker · reviewed October 2026
gs.info() / gs.warn() / gs.error() / gs.debug()
# Writes to the system log at a level. Use {0}, {1} placeholders for values.
gs.info('Closed {0} incidents for {1}', count, groupName);
gs.error('Integration failed: ' + errorMessage);
gs.log() and gs.print() are not available in scoped apps; these work everywhere.
gs.getUserID() / gs.getUserName() / gs.getUserDisplayName()
# The logged-in user's sys_id, user name and display name.
var inc = new GlideRecord('incident');
inc.addQuery('caller_id', gs.getUserID());
inc.addActiveQuery();
inc.query();
Returns the logged-in user as an object, with hasRole() and isMemberOf().
var user = gs.getUser();
if (user.isMemberOf('Service Desk')) {
gs.info(user.getName() + ' is on the Service Desk');
}
True when the logged-in user has the role.
if (!gs.hasRole('itil')) {
gs.addErrorMessage('Only the service desk can reopen incidents.');
}
Admins pass every hasRole() check.
gs.getProperty('name', default)
# Reads a system property, with a default when it is not set. Always returns a string.
var limit = parseInt(gs.getProperty('x_acme_itsm.max_items', '50'), 10);
var groupId = gs.getProperty('x_acme_itsm.major_incident.group');
The place for sys_ids and URLs, instead of hard-coding them.
gs.addInfoMessage() / gs.addErrorMessage()
# Shows a message at the top of the form for the current user.
gs.addInfoMessage('Incident ' + current.getValue('number') + ' was escalated.');
gs.eventQueue('event.name', record, parm1, parm2)
# Fires an event. Notifications and script actions listen for it.
gs.eventQueue('incident.escalated', current, current.getValue('assigned_to'), gs.getUserID());
Register the event in the Event Registry first.
True for null, undefined, an empty string or an empty GlideElement.
if (gs.nil(current.getValue('assignment_group'))) {
gs.addErrorMessage('Pick an assignment group first.');
}
gs.daysAgoStart(n) / gs.beginningOfToday() / gs.endOfToday()
# Date helpers that return date-time strings for queries.
var inc = new GlideRecord('incident');
inc.addQuery('sys_created_on', '>=', gs.daysAgoStart(7));
inc.query();
gs.getMessage('key', args)
# Returns a translated message from the Messages table, with {0} placeholders filled in.
var text = gs.getMessage('Hello {0}', [gs.getUserDisplayName()]);
Returns a new random 32-character id.
var correlationId = gs.generateGUID();
gs.tableExists('table')
# True when the table exists on this instance.
if (gs.tableExists('u_vendor_contract')) {
gs.info('Contracts plugin is installed');
}
Frequently asked questions
Why does gs.log() not work in my scoped app?
gs.log() and gs.print() only exist in the global scope. Use gs.info(), gs.warn(), gs.error() or gs.debug(), which work everywhere.