GlideSystem - Scoped

The scoped GlideSystem (referred to by the variable name 'gs' in any server-side JavaScript) API provides a number of convenient methods to get information about the system, the current logged in user, etc.

Many of the GlideSystem methods facilitate the easy inclusion of dates in query ranges, and are most often used in filters and reporting.

Scoped GlideSystem - addErrorMessage(Object message)

Adds an error message for the current session.

Table 1. Parameters
Name Type Description
message Object The message to add.
Table 2. Returns
Type Description
void
gs.include("PrototypeServer");
  var ValidatePasswordStronger = Class.create();
  ValidatePasswordStronger.prototype = {
       process : function() {
          var user_password = request.getParameter("user_password");
          var min_len = 8;
          var rules = "Password must be at least " + min_len + 
             " characters long and contain a digit, an uppercase letter, and a lowercase letter.";
          if (user_password.length() < min_len) {
             gs.addErrorMessage("TOO SHORT: " + rules);
             return false;
          }
          var digit_pattern = new RegExp("[0-9]", "g");
          if (!digit_pattern.test(user_password)) {
             gs.addErrorMessage("DIGIT MISSING: " + rules);
             return false;
          }
          var upper_pattern = new RegExp("[A-Z]", "g");
          if (!upper_pattern.test(user_password)) {
             gs.addErrorMessage("UPPERCASE MISSING: " + rules);
             return false;
          }
          var lower_pattern = new RegExp("[a-z]", "g");
          if (!lower_pattern.test(user_password)) {
             gs.addErrorMessage("LOWERCASE MISSING: " + rules);
             return false;
          }
          return true; // password is OK
       }
  }

Scoped GlideSystem - addInfoMessage(Object message)

Adds an info message for the current session. This method is not supported for asynchronous business rules.

Table 3. Parameters
Name Type Description
message Object An info message object.
Table 4. Returns
Type Description
void
if ((!current.u_date1.nil()) && (!current.u_date2.nil())) {
  var start = current.u_date1.getGlideObject().getNumericValue();
  var end = current.u_date2.getGlideObject().getNumericValue();
  if (start > end) {
    gs.addInfoMessage('start must be before end');
    current.u_date1.setError('start must be before end');
    current.setAbortAction(true);
  }
}

Output:

Scoped GlideSystem - base64Encode(String source)

Creates a base64 string from the specified string.

Table 5. Parameters
Name Type Description
source String The string to be encoded.
Table 6. Returns
Type Description
String The base64 string.

Scoped GlideSystem - base64Decode(String source)

Returns an ASCII string from the specified base64 string.

Table 7. Parameters
Name Type Description
source String A base64 encoded string.
Table 8. Returns
Type Description
String The decoded string.

Scoped GlideSystem - beginningOfLastMonth()

Returns the date and time for the beginning of last month in GMT.

Table 9. Parameters
Name Type Description
None
Table 10. Returns
Type Description
String GMT beginning of last month, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - beginningOfLastWeek()

Returns the date and time for the beginning of last week in GMT.

Table 11. Parameters
Name Type Description
None
Table 12. Returns
Type Description
String GMT beginning of last week, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - beginningOfNextMonth()

Returns the date and time for the beginning of next month in GMT.

Table 13. Parameters
Name Type Description
None
Table 14. Returns
Type Description
String GMT beginning of next month, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - beginningOfNextWeek()

Returns the date and time for the beginning of next week in GMT.

Table 15. Parameters
Name Type Description
None
Table 16. Returns
Type Description
String The GMT beginning of next week, in the format yyyy-mm-dd hh:mm:ss.


      
    

Scoped GlideSystem - beginningOfNextYear()

Returns the date and time for the beginning of next year in GMT.

Table 17. Parameters
Name Type Description
None
Table 18. Returns
Type Description
String GMT beginning of next year, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - beginningOfThisMonth()

Returns the date and time for the beginning of this month in GMT.

Table 19. Parameters
Name Type Description
None
Table 20. Returns
Type Description
String GMT beginning of this month, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - beginningOfThisQuarter()

Returns the date and time for the beginning of this quarter in GMT.

Table 21. Parameters
Name Type Description
None
Table 22. Returns
Type Description
String GMT beginning of this quarter, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - beginningOfThisWeek()

Returns the date and time for the beginning of this week in GMT.

Table 23. Parameters
Name Type Description
None
Table 24. Returns
Type Description
String GMT beginning of this week, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - beginningOfThisYear()

Returns the date and time for the beginning of this year in GMT.

Table 25. Parameters
Name Type Description
None
Table 26. Returns
Type Description
String GMT beginning of this year, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - dateGenerate(String date, String range)

Generates a date and time for the specified date in GMT.

Table 27. Parameters
Name Type Description
date String Format: yyyy-mm-dd
range String Start, end, or a time in the 24 hour format hh:mm:ss.
Table 28. Returns
Type Description
String A date and time in the format yyyy-mm-dd hh:mm:ss. If range is start, the returned value is yyyy-mm-dd 00:00:00; If range is end the return value is yyyy-mm-dd 23:59:59.

Scoped GlideSystem - daysAgo(Number days)

Returns the date and time for a specified number of days ago.

Table 29. Parameters
Name Type Description
days Number Integer number of days
Table 30. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

function contractNoticeDue() {
    var gr = new GlideRecord("contract");
    gr.addQuery("u_contract_status", "Active");
    gr.query();
    while (gr.next()) {
        if ((gr.u_termination_date <= gs.daysAgo(-90)) && (gr.u_contract_duration == "Long")) {
            gr.u_contract_status = "In review";
        } 
        else if ((gr.u_termination_date <= gs.daysAgo(-50)) && (gr.u_contract_duration == "Medium")) {
            gr.u_contract_status = "In review";
        } 
        else if ((gr.u_termination_date <= gs.daysAgo(-10)) && (gr.u_contract_duration == "Short")) {
            gr.u_contract_status = "In review";
        }
    }
    gr.update();
}

Scoped GlideSystem - daysAgoEnd(Number days)

Returns the date and time for the end of the day a specified number of days ago.

Table 31. Parameters
Name Type Description
days Number Integer number of days
Table 32. Returns
Type Description
String GMT end of the day in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - daysAgoStart(Number days)

Returns the date and time for the beginning of the day a specified number of days ago.

Table 33. Parameters
Name Type Description
days String Integer number of days
Table 34. Returns
Type Description
String GMT start of the day in the format yyyy-mm-dd hh:mm:ss

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('state', 'requested');
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(5));
gr.query();

Scoped GlideSystem - debug(String message, Object parm1, Object parm2, Object parm3, Object parm4, Object parm5)

Writes a debug message to the system log.

Table 35. Parameters
Name Type Description
message String The log message with place holders for any variable arguments.
param1 Object (Optional) First variable argument.
param2 Object (Optional) Second variable argument.
param3 Object (Optional) Third variable argument.
param4 Object (Optional) Fourth variable argument.
param5 Object (Optional) Fifth variable argument.
Table 36. Returns
Type Description
void
gs.debug("This is a debug message");
var myFirstName = "Abel";
var myLastName = "Tuter";
gs.debug("This is a debug message from {0}.{1}", myFirstName, myLastName);
Output:
This is a debug message (sys.scripts extended logging)
This is a debug message from Abel.Tuter (sys.scripts extended logging)

Scoped GlideSystem - endOfLastMonth()

Returns the date and time for the end of last month in GMT.

Table 37. Parameters
Name Type Description
None
Table 38. Returns
Type Description
String GMT end of last month, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - endOfLastWeek()

Returns the date and time for the end of last week in GMT.

Table 39. Parameters
Name Type Description
None
Table 40. Returns
Type Description
String GMT end of last week, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - endOfLastYear()

Returns the date and time for the end of last year in GMT.

Table 41. Parameters
Name Type Description
None
Table 42. Returns
Type Description
String GMT in format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - endOfNextMonth()

Returns the date and time for the end of next month in GMT.

Table 43. Parameters
Name Type Description
None
Table 44. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - endOfNextWeek()

Returns the date and time for the end of next week in GMT.

Table 45. Parameters
Name Type Description
None
Table 46. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss


      
    

Scoped GlideSystem - endOfNextYear()

Returns the date and time for the end of next year in GMT.

Table 47. Parameters
Name Type Description
None
Table 48. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - endOfThisMonth()

Returns the date and time for the end of this month in GMT.

Table 49. Parameters
Name Type Description
None
Table 50. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - endOfThisQuarter()

Returns the date and time for the end of this quarter in GMT.

Table 51. Parameters
Name Type Description
None
Table 52. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - endOfThisWeek()

Returns the date and time for the end of this week in GMT.

Table 53. Parameters
Name Type Description
None
Table 54. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - endOfThisYear()

Returns the date and time for the end of this year in GMT.

Table 55. Parameters
Name Type Description
None
Table 56. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - error(String message, Object parm1, Object parm2, Object parm3, Object parm4, Object parm5)

Writes an error message to the system log.

This method accepts up to five variable arguments (varargs) in the message using the Java MessageFormat placeholder replacement pattern.

Table 57. Parameters
Name Type Description
message String The log message with place holders for any variable arguments.
param1 Object (Optional) First variable argument.
param2 Object (Optional) Second variable argument.
param3 Object (Optional) Third variable argument.
param4 Object (Optional) Fourth variable argument.
param5 Object (Optional) Fifth variable argument.
Table 58. Returns
Type Description
void
gs.error("This is an error message");
var myFirstName = "Abel";
var myLastName = "Tuter";
gs.error("This is an error message from {0}.{1}", myFirstName, myLastName);
Output:
This is an error message
This is an error message from Abel.Tuter

Scoped GlideSystem - eventQueue(String name, Object instance, String parm1, String parm2, String parm3)

Queues an event for the event manager.

Table 59. Parameters
Name Type Description
name String Name of the event being queued.
instance Object A GlideRecord object, such as "current".
parm1 String (Optional) Saved with the instance if specified.
parm2 String (Optional) Saved with the instance if specified.
parm3 String The name of the queue.
Table 60. Returns
Type Description
void
if (current.operation() != 'insert' && current.comments.changes()) {
    gs.eventQueue('incident.commented', current, gs.getUserID(), gs.getUserName());
}

Scoped GlideSystem - eventQueueScheduled(String name, Object instance, String parm1, String parm2, Object expiration)

Alerts the user if event was not scheduled. Does nothing if the event is scheduled.

Table 61. Parameters
Name Type Description
name String Name of the event being queued.
instance Object A GlideRecord object, such as "current".
parm1 String (Optional) Saved with the instance if specified.
parm2 String (Optional) Saved with the instance if specified.
expiration Object When the event expires.
Table 62. Returns
Type Description
void

Scoped GlideSystem - executeNow(GlideRecord job)

Executes a job for a scoped application.

You can only use this method on a job in the same application as the script calling this method.

Table 63. Parameters
Name Type Description
job GlideRecord The job to be run.
Table 64. Returns
Type Description
String Returns the sysID of the scheduled job. Returns null if the job is global.

Scoped GlideSystem - generateGUID()

Generates a GUID that can be used when a unique identifier is required.

Table 65. Parameters
Name Type Description
None
Table 66. Returns
Type Description
String A 32-character hexadecimal GUID.
personalId = gs.generateGUID();
gs.info(personalId);

Output: af770511ff013100e04bfffffffffff6

Scoped GlideSystem - getCallerScopeName()

Gets the caller scope name; returns null if there is no caller.

Table 67. Parameters
Name Type Description
None
Table 68. Returns
Type Description
String The caller's scope name, or null if there is no caller.

This example shows two script includes that are set to Accessible from all application scopes. One script include is created within app_scope_a.

var Scopea = Class.create(); 
 
Scopea.prototype = { 
    initialize: function() { 
    }, 
 
    callerScope: function() { 
        var scopeb = new app_scope_b.Scopeb(); 
        return scopeb.callerscope(); 
    }, 
 
    type: 'Scopea' 
}

Output:

This example shoes another script include created within app_scope_b.

var Scopeb = Class.create(); 
 
Scopeb.prototype = { 
    initialize: function() { 
        this._constructorCallerScope = gs.getCallerScopeName(); 
    }, 
 
    callerscope: function() { 
        return gs.getCallerScopeName(); 
    }, 
 
    getConstructorCallerScope: function() { 
        return this._constructorCallerScope; 
    }, 
 
    type: 'Scopeb' 
}

Output:

This script can be used within scope app_scope_a to get the scope name of the caller—in this case app_scope_b.

gs.info(new Scopea().getCallerScopeName());

Output:

Scoped GlideSystem - getCssCacheVersionString()

Gets a string representing the cache version for a CSS file.

Table 69. Parameters
Name Type Description
None
Table 70. Returns
Type Description
String The CSS cache version.
var verStr = gs.getCssCacheVersionString();
gs.info(verStr);

Output: _d82979516f0171005be8883e6b3ee4cf&theme=

Scoped GlideSystem - getCurrentApplicationId()

Gets the ID of the current application as set using the Application Picker.

Table 71. Parameters
Name Type Description
None
Table 72. Returns
Type Description
String The current application's sys_id, or global in none is set.
var currentId = gs.getCurrentApplicationId();
gs.info(currentId);

Output: 04936cb16f30b1005be8883e6b3ee4e0

Scoped GlideSystem - getCurrentScopeName()

Gets the name of the current scope.

Table 73. Parameters
Name Type Description
None
Table 74. Returns
Type Description
String The current scope name.
var currentScope = gs.getCurrentScopeName();
gs.info(currentScope);

Scoped GlideSystem - getErrorMessages()

Returns the list of error messages for the session that were added by addErrorMessage().

Table 75. Parameters
Name Type Description
None
Table 76. Returns
Type Description
String List of error messages

Scoped GlideSystem - getEscapedMessage(String id, Array args)

Retrieves a message from UI messages with HTML special characters replaced with escape sequences, for example, & becomes &amp;.

Table 77. Parameters
Name Type Description
id String The ID of the message.
args Array (Optional) a list of strings or other values defined by java.text.MessageFormat, which allows you to produce language-neutral messages for display to users.
Table 78. Returns
Type Description
String The UI message with HTML special characters replaced with escape sequences.
var myMessage = gs.geEscapedMessage("Hello {0}", ["mom"]);

Scoped GlideSystem - getMessage(String id, Array args)

Retrieves a message from UI messages.

Table 79. Parameters
Name Type Description
id String The ID of the message.
args Array (Optional) a list of strings or other values defined by java.text.MessageFormat, which allows you to produce language-neutral messages for display to users.
Table 80. Returns
Type Description
String The UI message.
var my_message = '${gs.getMessage("This is a message.")}'; 
alert(my_message);

Scoped GlideSystem - getProperty(String key, Object alt)

Gets the value of a Glide property. If the property is not found, returns an alternate value.

Table 81. Parameters
Name Type Description
key String The key for the property whose value should be returned.
alt Object (Optional) Alternate object to return if the property is not found.
Table 82. Returns
Type Description
String The value of the Glide property, or the alternate object defined above.
var attachment_link = gs.getProperty('glide.servlet.uri');
gs.info(attachment_link);

Output: https://instance.service-now.com/

Scoped GlideSystem - getSession()

Gets a reference to the current Glide session.

Table 83. Parameters
Name Type Description
None
Table 84. Returns
Type Description
String A reference for the current session.
if (!gs.hasRole("admin") && !gs.hasRole("user_admin") && gs.getSession().isInteractive()) {
  current.addQuery("active", "true");
}

Output:

Scoped GlideSystem - getSessionID()

Retrieves the GlideSession session ID.

Table 85. Parameters
Name Type Description
None
Table 86. Returns
Type Description
String The session ID.
var myUserObject = gs.getSessionID();
gs.info(myUserObject);
Output:
A0D4E5416F3F21005BE8883E6B3EE4B8

Scoped GlideSystem - getSessionToken()

This method is no longer available. Instead, use gs.getSession().getSessionToken().

Table 87. Parameters
Name Type Description
None
Table 88. Returns
Type Description
String The session token.

Scoped GlideSystem - getTimeZoneName()

Returns the name of the time zone associated with the current user.

Table 89. Parameters
Name Type Description
None
Table 90. Returns
Type Description
String The time zone name.
gs.info(gs.getTimeZoneName());

Output:

Scoped GlideSystem - getUrlOnStack()

Gets the current URI for the session.

Table 91. Parameters
Name Type Description
None
Table 92. Returns
Type Description
String The URI.
gs.info(gs.getUrlOnStack());

Output:

Scoped GlideSystem - getUser()

Returns a reference to the scoped GlideUser object for the current user.

See GlideUser for a list of available methods.
Table 93. Parameters
Name Type Description
None
Table 94. Returns
Type Description
GlideUser Reference to a scoped user object.
var myUserObject = gs.getUser();

Scoped GlideSystem - getUserDisplayName()

Gets the display name of the current user.

Table 95. Parameters
Name Type Description
None
Table 96. Returns
Type Description
String The name field of the current user. Returns Abel Tuter, as opposed to abel.tuter.
gs.info(gs.getUserDisplayName());

Output:

Scoped GlideSystem - getUserID()

Gets the sys_id of the current user.

Table 97. Parameters
Name Type Description
None
Table 98. Returns
Type Description
String The sys_id of the current user.
gs.info(gs.getUserID());

Output:

Scoped GlideSystem - getUserName()

Gets the user name, or user id, of the current user.

Table 99. Parameters
Name Type Description
None
Table 100. Returns
Type Description
String The user name of the current user.
gs.info(gs.getUserName());

Output:

Scoped GlideSystem - hasRole(Object role)

Determines if the current user has the specified role.

Table 101. Parameters
Name Type Description
role Object The role to check.
Table 102. Returns
Type Description
Boolean True if the user had the role. Returns true for users with the administrator role.
if (!gs.hasRole("admin") && !gs.hasRole("groups_admin")  && gs.getSession().isInteractive()) {
  var qc = current.addQuery("u_hidden", "!=", "true"); //cannot see hidden groups... 
  qc.addOrCondition("sys_id", "javascript:getMyGroups()"); //...unless in the hidden group
  gs.info("User has admin and groups admin roles");
}
else {
  gs.info("User does not have both admin and groups admin roles");
}

Output:

Scoped GlideSystem - hoursAgo(Number hours)

Returns the date and time for a specified number of hours ago.

Table 103. Parameters
Name Type Description
hours Number Integer number of hours
Table 104. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

if (current.operation() == 'insert') {
 // If no due date was specified, calculate a default
 if (current.due_date == '') {
 
  if (current.urgency == '1') {
   // Set due date to 4 hours ahead of current time
   current.due_date = gs.hoursAgo(-4);
  }
 
  if (current.urgency == '2') {
   // Set due date to 2 days ahead of current time
   current.due_date = gs.daysAgo(-2);
  }
 
  if (current.urgency == '3') {
   // Set due date to 7 days ahead of current time
   current.due_date = gs.daysAgo(-7);
  }
 }
}

Scoped GlideSystem - hoursAgoEnd(Number hours)

Returns the date and time for the end of the hour a specified number of hours ago.

Table 105. Parameters
Name Type Description
hours Number Integer number of hours
Table 106. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - hoursAgoStart(Number hours)

Returns the date and time for the start of the hour a specified number of hours ago.

Table 107. Parameters
Name Type Description
hours Number Integer number of hours
Table 108. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - include(String name)

Provides a safe way to call from the sandbox, allowing only trusted scripts to be included.

Table 109. Parameters
Name Type Description
name String The name fo the script to include.
Table 110. Returns
Type Description
Boolean True if the include worked.

This example gets the PrototypeServer in the current script context.

gs.include("PrototypeServer");

Output:

Scoped GlideSystem - info(String message, Object parm1, Object parm2, Object parm3, Object parm4, Object parm5)

Writes an info message to the system log.

Table 111. Parameters
Name Type Description
message String The log message with place holders for any variable arguments.
param1 Object (Optional) First variable argument.
param2 Object (Optional) Second variable argument.
param3 Object (Optional) Third variable argument.
param4 Object (Optional) Fourth variable argument.
param5 Object (Optional) Fifth variable argument.
Table 112. Returns
Type Description
void
gs.info("This is an info message");
var myFirstName = "Abel";
var myLastName = "Tuter";
gs.info("This is an info message from {0}.{1}", myFirstName, myLastName);
Output:
This is an info message
This is an info message from Abel.Tuter

Scoped GlideSystem - isDebugging()

Determines if debugging is active for a specific scope.

Table 113. Parameters
Name Type Description
None
Table 114. Returns
Type Description
Boolean True if either session debugging is active or the log level is set to debug for the specified scope.
gs.debug("This is a log message");
var myFirstName = "Abel";
var myLastName = "Tuter";
gs.debug("This is a log message from {0}.{1}", myFirstName, myLastName);
gs.info(gs.isDebugging());

Output:

Scoped GlideSystem - isInteractive()

Checks if the current session is interactive. An example of an interactive session is when a user logs in normally. An example of a non-interactive session is using a SOAP request to retrieve data.

Table 115. Parameters
Name Type Description
None
Table 116. Returns
Type Description
Boolean True if the session is interactive.
if (!gs.hasRole("admin") && gs.getSession().isInteractive()) {
    var qc1 = current.addQuery('u_group',"");
    var gra = new GlideRecord('sys_user_grmember');
    gra.addQuery('user', gs.getUserID());
    gra.query();
    while (gra.next()) {
        qc1.addOrCondition('u_group', gra.group);
    }
}

Output:

Scoped GlideSystem - isLoggedIn()

Determines if the current user is currently logged in.

Table 117. Parameters
Name Type Description
None
Table 118. Returns
Type Description
Boolean True if the current user is logged in.
gs.info(gs.isLoggedIn());

Output:

Scoped GlideSystem - isMobile()

You can determine if a request comes from a mobile device.

This method can be used in UI action conditions and business rules.

Table 119. Parameters
Name Type Description
None
Table 120. Returns
Type Description
Boolean True if the request comes from a mobile device; otherwise, false.
if (gs.isMobile())
  gs.info("submitted from mobile UI");
 else 
   gs.info("NOT submitted from mobile UI");

Scoped GlideSystem - monthsAgo(Number months)

Returns the date and time for a specified number of months ago.

Table 121. Parameters
Name Type Description
months Number Integer number of months
Table 122. Returns
Type Description
String GMT on today's date of the specified month, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - minutesAgoEnd(Number minutes)

Returns the date and time for the end of the minute a specified number of minutes ago.

Table 123. Parameters
Name Type Description
minutes Number Integer number of minutes
Table 124. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - minutesAgoStart(Number minutes)

Returns the date and time for the start of the minute a specified number of minutes ago.

Table 125. Parameters
Name Type Description
minutes Number Integer number of minutes
Table 126. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - monthsAgoStart(Number months)

Returns the date and time for the start of the month a specified number of months ago.

Table 127. Parameters
Name Type Description
months Number Integer number of months
Table 128. Returns
Type Description
String GMT start of the month the specified number of months ago, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - nil(Object o)

Queries an object and returns true if the object is null, undefined, or contains an empty string.

Table 129. Parameters
Name Type Description
o Object The object to be checked.
Table 130. Returns
Type Description
Boolean True if the object is null, undefined, or contains an empty string; otherwise, returns false.
var gr = new GlideRecord();
gs.info(gs.nil(gr));

Output:

Scoped GlideSystem - quartersAgoEnd(Number quarters)

Returns the date and time for the last day of the quarter for a specified number of quarters ago.

Table 131. Parameters
Name Type Description
quarters Number Integer number of quarters
Table 132. Returns
Type Description
String GMT end of the quarter that was the specified number of quarters ago, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - quartersAgoStart(Number quarters)

Returns the date and time for the first day of the quarter for a specified number of quarters ago.

Table 133. Parameters
Name Type Description
quarters Number Integer number of quarters
Table 134. Returns
Type Description
String GMT end of the month that was the specified number of quarters ago, in the format yyyy-mm-dd hh:mm:ss

Scoped GlideSystem - setProperty(String key, String value, String description)

Sets the specified key to the specified value if the property is within the script's scope.

Note: Care should be taken when setting system properties (sys_properties) using this method as it causes a system-wide cache flush. Each flush can cause system degradation while the caches rebuild. If a value must be updated often, it should not be stored as a system property. In general, you should only place values in the sys_properties table that do not frequently change.
Table 135. Parameters
Name Type Description
key String The key for the property to be set.
value String The value of the property to be set.
description String A description of the property.
Table 136. Returns
Type Description
void
gs.setProperty("glide.foo","bar","foo");
gs.info(gs.getProperty("glide.foo"));

Output: bar

Scoped GlideSystem - setRedirect(Object o)

Sets the redirect URI for this transaction, which then determines the next page the user will see.

Table 137. Parameters
Name Type Description
o Object URI object or URI string to set as the redirect
Table 138. Returns
Type Description
void
gs.setRedirect("com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=d41ce5bac611227a0167f4bf8109bf70&sysparm_user=" 
+ current.sys_id + "&sysparm_email=" + current.email)

Output:

Scoped GlideSystem - tableExists(String name)

Determines if a database table exists.

Table 139. Parameters
Name Type Description
name String Name of the table to check for existence.
Table 140. Returns
Type Description
Boolean True if the table exists. False if the table was not found.
gs.info(gs.tableExists('incident'));

Output:

Scoped GlideSystem - urlEncode(String url)

Encodes non-ASCII characters, unsafe ASCII characters, and spaces so the returned string can be used on the Internet. Uses UTF-8 encoding. Uses percent (%) encoding.

Table 141. Parameters
Name Type Description
url String The string to be encoded.
Table 142. Returns
Type Description
String A string with non-ASCII characters, unsafe ASCII characters, and spaces encoded.

Scoped GlideSystem - urlDecode(String url)

Replaces UTF-8 encoded characters with ASCII characters.

Table 143. Parameters
Name Type Description
url String A string with UTF-8 percent (%) encoded characters.
Table 144. Returns
Type Description
String A string with encoded characters replaced with ASCII characters.

Scoped GlideSystem - warn(String message, Object parm1, Object parm2, Object parm3, Object parm4, Object parm5)

Writes a warning message to the system log.

Table 145. Parameters
Name Type Description
message String The log message with place holders for any variable arguments.
param1 Object (Optional) First variable argument.
param2 Object (Optional) Second variable argument.
param3 Object (Optional) Third variable argument.
param4 Object (Optional) Fourth variable argument.
param5 Object (Optional) Fifth variable argument.
Table 146. Returns
Type Description
void
gs.warn("This is a warning");
var myFirstName = "Abel";
var myLastName = "Tuter";
gs.warn("This is a warning from {0}.{1}", myFirstName, myLastName);
Output:
This is a warning
This is a warning from Abel.Tuter

Scoped GlideSystem - xmlToJSON(String xmlString)

Takes an XML string and returns a JSON object.

Table 147. Parameters
Name Type Description
xmlString String The XML string to be converted.
Table 148. Returns
Type Description
Object A JSON object representing the XML string. Null if unable to process the XML string.
var jsonObject = gs.xmlToJSON(xmlString);

Scoped GlideSystem - yearsAgo(Number years)

Gets a date and time for a certain number of years ago.

Table 149. Parameters
Name Type Description
years Number An integer number of years
Table 150. Returns
Type Description
String GMT beginning of the year that is the specified number of years ago, in the format yyyy-mm-dd hh:mm:ss.


      
    

Scoped GlideSystem - yesterday()

Returns yesterday's time (24 hours ago).

Table 151. Parameters
Name Type Description
None
Table 152. Returns
Type Description
String GMT for 24 hours ago, in the format yyyy-mm-dd hh:mm:ss