Tushar
Kilo Sage

 

GlideSystem (gs) - the utility belt

GlideSystem is the utility API available in all server-side scripts via the gs global object. It provides methods that are used constantly across the platform.

 

  • Logging - gs.info(), gs.warn(), gs.error(), gs.debug() - the correct way to log information from server-side scripts. Logs appear in the System Log and are filterable by level. gs.debug() messages only appear when debug logging is enabled - use it for development-time information that should not appear in production logs.
  • User context - gs.getUserID(), gs.getUserName(), gs.hasRole() - methods that return information about the current session user. Used in access control logic, personalisation, and audit trail creation.
  • System properties - gs.getProperty() - reads values from System Properties (sys_properties) - the platform's configuration store. Hard-coding values in scripts is bad practice. Storing configurable values in System Properties and reading them with gs.getProperty() makes scripts maintainable without code changes.
  • Date and time - gs.now(), gs.nowDateTime(), gs.daysAgo() - utility methods for date calculations. ServiceNow's date/time handling has specific requirements - using gs methods ensures timezone and format consistency.

 

GlideAggregate - counting and summing at scale

GlideAggregate performs aggregate database operations - COUNT, SUM, AVG, MIN, MAX - without loading individual records into memory. It is the correct tool when you need statistics about a set of records rather than the records themselves.

The performance difference between counting records in a GlideRecord loop versus using GlideAggregate.addAggregate('COUNT') can be dramatic on large tables. A GlideRecord count loop on 10,000 records loads all 10,000 into memory. GlideAggregate returns a single count from the database without loading any records. In reporting scripts, Scheduled Jobs, and any context where you need aggregate data, GlideAggregate is the correct choice.

Version history
Last update:
53m ago
Updated by:
Contributors