What is GlideSystem (gs)?

The GlideSystem (gs) object provides access to system methods and information. It's available in all server-side scripts and offers utilities for logging, user management, properties, and more.

Server-Side Only

The gs object is ONLY available in server-side scripts (Business Rules, Script Includes, etc.). Not available in client scripts.

Logging Methods

Log Messages
// Log levels (shown in System Log)
gs.log('This is a log message');  // INFO level
gs.info('Information message');    // INFO level
gs.warn('Warning message');        // WARNING level
gs.error('Error message');         // ERROR level
gs.debug('Debug message');         // DEBUG level

// Log with source (helps identify where log came from)
gs.log('Processing incident', 'MyScriptInclude');
gs.error('Failed to update record', 'BusinessRule.UpdateIncident');

// Example in Business Rule
if (current.priority == '1' && current.assignment_group.nil()) {
    gs.error('Critical incident without assignment group: ' + current.number);
}
Best Practice

Use appropriate log levels. Use gs.info() for normal operations, gs.warn() for potential issues, gs.error() for failures. View logs at System Logs > System Log.

User Information

Get Current User Info
// Get current user's sys_id
var userID = gs.getUserID();

// Get current user's username
var userName = gs.getUserName();  // Returns 'john.doe'

// Get user's display name
var displayName = gs.getUserDisplayName();  // Returns 'John Doe'

// Check if user has a role
if (gs.hasRole('admin')) {
    // User has admin role
}

if (gs.hasRole('itil,admin')) {
    // User has EITHER itil OR admin role (OR logic)
}

// Check if user is impersonating
if (gs.isImpersonating()) {
    gs.log('User is impersonating');
}

// Example: Auto-assign to current user
if (current.assigned_to.nil()) {
    current.assigned_to = gs.getUserID();
}

User Messages

Display Messages to Users
// Info message (blue banner)
gs.addInfoMessage('Record has been updated successfully');

// Error message (red banner)
gs.addErrorMessage('Failed to update record: Missing required field');

// Example in Business Rule
if (current.priority == '1' && current.assignment_group.nil()) {
    gs.addErrorMessage('Critical incidents must have an assignment group');
    current.setAbortAction(true);  // Prevent save
}

// Success message
gs.addInfoMessage('Incident ' + current.number + ' has been created');

System Properties

Get/Set System Properties
// Get system property value
var maxAttachmentSize = gs.getProperty('glide.attachment.max_size');
var instanceName = gs.getProperty('instance_name');

// Get property with default value if not found
var defaultPriority = gs.getProperty('custom.default.priority', '3');

// Set property value (requires admin role)
gs.setProperty('custom.my.property', 'value');

// Example: Use property for configuration
var autoAssignEnabled = gs.getProperty('custom.incident.auto_assign', 'false');
if (autoAssignEnabled == 'true') {
    // Auto-assign logic
}

Date/Time Methods

Date/Time Utilities
// Get current date/time
var now = gs.now();  // Returns: '2024-10-24 10:30:00'
var nowDateTime = gs.nowDateTime();  // Returns GlideDateTime object
var nowNoTZ = gs.nowNoTZ();  // Without timezone conversion

// Days ago
var sevenDaysAgo = gs.daysAgo(7);  // Date 7 days ago
var startOfToday = gs.daysAgoStart(0);  // Start of today
var endOfToday = gs.daysAgoEnd(0);  // End of today

// Months ago
var oneMonthAgo = gs.monthsAgo(1);
var startOfMonth = gs.monthsAgoStart(0);
var endOfMonth = gs.monthsAgoEnd(0);

// Begin/End of specific periods
var startOfWeek = gs.beginningOfThisWeek();
var endOfWeek = gs.endOfThisWeek();
var startOfMonth = gs.beginningOfThisMonth();
var endOfMonth = gs.endOfThisMonth();
var startOfYear = gs.beginningOfThisYear();

// Date/Time calculations
var yesterday = gs.daysAgo(1);
var nextWeek = gs.daysAgo(-7);  // Negative for future

// Example: Query records from last 30 days
var gr = new GlideRecord('incident');
gr.addQuery('sys_created_on', '>', gs.daysAgoStart(30));
gr.query();

Utility Methods

Common Utility Methods
// Generate GUID
var newGUID = gs.generateGUID();

// Get message from sys_ui_message table
var msg = gs.getMessage('Record not found');
var msgWithParams = gs.getMessage('Hello {0}, you have {1} tasks', [userName, taskCount]);

// Nil check (check if value is null or empty)
if (gs.nil(current.assignment_group)) {
    // Field is empty
}

// Get session info
var sessionID = gs.getSessionID();
var clientIP = gs.getClientIP();

// URL utilities
var currentURL = gs.getProperty('glide.servlet.uri');
var baseURL = gs.getProperty('glide.servlet.uri') + '/nav_to.do?uri=' + current.getLink();

// Execute business rule
gs.eventQueue('incident.assigned', current);

// Sleep (use sparingly)
gs.sleep(1000);  // Sleep for 1 second (1000 ms)

// Example: Generate unique number
var uniqueID = gs.generateGUID();
gs.log('Generated ID: ' + uniqueID);

Script Evaluation

Evaluate Scripts and Expressions
// Evaluate script from string (use carefully!)
var result = gs.eval('2 + 2');  // Returns 4

// Check if running in background
if (gs.isInteractive()) {
    // Running interactively (from UI)
} else {
    // Running in background (scheduled job, etc.)
}

// Get current scope
var currentScope = gs.getCurrentScopeName();  // Returns 'global' or app scope

// Include script
gs.include('UtilityScriptInclude');

CSA & CAD Exam Questions (15 Questions)

How do you get the current user's sys_id in a server script? Q1
CSA
  • A) gs.getUser()
  • B) gs.getUserID()
  • C) gs.getUserSysID()
  • D) gs.currentUser()
Show Answer
Correct Answer: B
gs.getUserID() returns the sys_id of the currently logged-in user. Also available: gs.getUserName() for username, gs.getUserDisplayName() for full name.
Which method displays an error message to the user? Q2
CSA
  • A) gs.showError('message')
  • B) gs.addErrorMessage('message')
  • C) gs.error('message')
  • D) gs.displayError('message')
Show Answer
Correct Answer: B
gs.addErrorMessage() displays a red error banner to the user. gs.error() writes to system logs. Also: gs.addInfoMessage() for info messages.
How do you get a date from 7 days ago? Q3
CSA
  • A) gs.daysAgo(7)
  • B) gs.subtractDays(7)
  • C) gs.getDate(-7)
  • D) gs.pastDays(7)
Show Answer
Correct Answer: A
gs.daysAgo(7) returns a date 7 days ago. Use daysAgoStart() for beginning of day, daysAgoEnd() for end of day. Negative values for future dates.
Where can you use the gs object? Q4
CSA
  • A) Only in Business Rules
  • B) In all server-side scripts
  • C) In client scripts
  • D) In both client and server scripts
Show Answer
Correct Answer: B
gs is available in ALL server-side scripts: Business Rules, Script Includes, Scheduled Jobs, UI Actions (server side), etc. NOT available in client scripts.
How do you check if a user has a specific role? Q5
CSA
  • A) gs.checkRole('admin')
  • B) gs.hasRole('admin')
  • C) gs.userHasRole('admin')
  • D) gs.validateRole('admin')
Show Answer
Correct Answer: B
gs.hasRole('role_name') returns true if current user has that role. Use comma-separated for OR logic: gs.hasRole('admin,itil') checks if user has admin OR itil.
What does gs.now() return? Q6
CSA
  • A) GlideDateTime object
  • B) Current date/time as string
  • C) Unix timestamp
  • D) JavaScript Date object
Show Answer
Correct Answer: B
gs.now() returns current date/time as a string in format '2024-10-24 10:30:00'. Use gs.nowDateTime() to get GlideDateTime object.
How do you get a system property value? Q7
CAD
  • A) gs.getProperty('property.name')
  • B) gs.property('property.name')
  • C) gs.getSystemProperty('property.name')
  • D) gs.readProperty('property.name')
Show Answer
Correct Answer: A
gs.getProperty('name') retrieves system property value. Can provide default: gs.getProperty('name', 'default_value'). Set with gs.setProperty().
What method generates a globally unique identifier? Q8
CAD
  • A) gs.createGUID()
  • B) gs.generateGUID()
  • C) gs.newGUID()
  • D) gs.getGUID()
Show Answer
Correct Answer: B
gs.generateGUID() generates a 32-character globally unique identifier. Useful for creating unique values.
How do you check if a value is null or empty? Q9
CAD
  • A) gs.isEmpty(value)
  • B) gs.nil(value)
  • C) gs.isNull(value)
  • D) gs.checkNull(value)
Show Answer
Correct Answer: B
gs.nil(value) returns true if value is null, undefined, or empty string. Example: if (gs.nil(current.assignment_group)) { }
Which gs method writes to the system log? Q10
CSA
  • A) gs.log()
  • B) gs.write()
  • C) gs.print()
  • D) gs.console()
Show Answer
Correct Answer: A
gs.log() writes INFO level messages to system log. Also: gs.info(), gs.warn(), gs.error(), gs.debug() for different log levels.
How do you get the start of the current week? Q11
CAD
  • A) gs.startOfWeek()
  • B) gs.beginningOfThisWeek()
  • C) gs.weekStart()
  • D) gs.thisWeekStart()
Show Answer
Correct Answer: B
gs.beginningOfThisWeek() returns start of current week. Also: endOfThisWeek(), beginningOfThisMonth(), beginningOfThisYear().
What does gs.getUserName() return? Q12
CSA
  • A) User's sys_id
  • B) User's full name
  • C) User's username/login
  • D) User's email
Show Answer
Correct Answer: C
gs.getUserName() returns the username/login (e.g., 'john.doe'). For full name use gs.getUserDisplayName(), for sys_id use gs.getUserID().
How do you retrieve a message from sys_ui_message table? Q13
CAD
  • A) gs.getUIMessage('key')
  • B) gs.getMessage('key')
  • C) gs.fetchMessage('key')
  • D) gs.readMessage('key')
Show Answer
Correct Answer: B
gs.getMessage('key') retrieves messages from sys_ui_message. Supports parameters: gs.getMessage('Hello {0}', [name]).
What does gs.isInteractive() check? Q14
CAD
  • A) If user is logged in
  • B) If script is running from UI (not background)
  • C) If form is in edit mode
  • D) If user is interacting with the page
Show Answer
Correct Answer: B
gs.isInteractive() returns true if script is running from UI interaction, false if running in background (scheduled job, async business rule).
Can gs.addInfoMessage() be used in async business rules? Q15
CAD
  • A) Yes, it works in all business rules
  • B) No, user messages don't display in async context
  • C) Yes, but only for admin users
  • D) No, use gs.log() instead
Show Answer
Correct Answer: B
User messages (addInfoMessage, addErrorMessage) only display when script runs interactively. Async business rules run in background, so messages aren't shown. Use gs.log() for background logging.

gs Quick Reference

  • gs.getUserID() - User sys_id
  • gs.getUserName() - Username
  • gs.hasRole('role') - Check role
  • gs.addInfoMessage() - Info banner
  • gs.addErrorMessage() - Error banner
  • gs.log() - Write to logs
  • gs.now() - Current time
  • gs.daysAgo(n) - Date n days ago
  • gs.getProperty() - System property
  • gs.nil(value) - Check null/empty