GlideSystem - Global

The 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.

GlideSystem - addErrorMessage(Object message)

Adds an error message for the current session.

Use getErrorMessages() to retrieve a list of error messages currently being shown.

Table 1. Parameters
Name Type Description
message Object The message to add.
Table 2. Returns
Type Description
void

Scoped equivalent

To use the addErrorMessage() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - addErrorMessage(Object message).

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
       }
  }
[edit]

GlideSystem - addInfoMessage(Object message)

Adds an info message for the current session.

Use getInfoMessages() to retrieve the list of info messages being shown. This method is not supported for asynchronous business rules and cannot be used within transform scripts.

Table 3. Parameters
Name Type Description
message Object The message to add.
Table 4. Returns
Type Description
void

Scoped equivalent

To use the addInfoMessage() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - addInfoMessage(Object message).

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);
  }
}

GlideSystem - addMessage(String type, Object message)

Adds a message for the current session.

Table 5. Parameters
Name Type Description
type String Type of message
message Object The message
Table 6. Returns
Type Description
void

gs.include("FormInfoHeader");
var fi = new FormInfoHeader();
var s = 'An incident ' + current.number + ' has been opened for your request.<br/>';
s += 'The IT department will contact you when the password is reset or for further information.<br/>';
//s += 'You can track status from the <a href="home.do" class="breadcrumb" >Home Page</a> <br/>';
fi.addMessage(s);
producer.redirect = 'home.do?sysparm_view=ess';

GlideSystem - beginningOfLastMonth()

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

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

Scoped equivalent

To use the beginningOfLastMonth() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - beginningOfLastMonth().


      
    

GlideSystem - beginningOfLastWeek()

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

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

Scoped equivalent

To use the beginningOfLastWeek() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - beginningOfLastWeek().


      
    

GlideSystem - beginningOfNextMonth()

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

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

Scoped equivalent

To use the beginningOfNextMonth() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - beginningOfNextMonth().


      
    

GlideSystem - beginningOfNextWeek()

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

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


      
    

GlideSystem - beginningOfNextYear()

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

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

Scoped equivalent

To use the beginningOfNextYear() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - beginningOfNextYear().


      
    

GlideSystem - beginningOfThisMonth()

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

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

Scoped equivalent

To use the beginningOfThisMonth() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - beginningOfThisMonth().


      
    

GlideSystem - beginningOfThisQuarter()

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

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

Scoped equivalent

To use the beginningOfThisQuarter() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - beginningOfThisQuarter().


      
    

GlideSystem - beginningOfThisWeek()

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

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

Scoped equivalent

To use the beginningOfThisWeek() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - beginningOfThisWeek().


      
    

GlideSystem - beginningOfThisYear()

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

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

Scoped equivalent

To use the beginningOfThisYear() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - beginningOfThisYear().


      
    

GlideSystem - beginningOfToday()

Gets the date and time for the beginning of today in GMT.

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


      
    

GlideSystem - beginningOfYesterday()

Gets the date and time for the beginning of yesterday in GMT.

Table 27. Parameters
Name Type Description
None
Table 28. Returns
Type Description
String The GMT beginning of yesterday, in the format yyyy-mm-dd hh:mm:ss.


      
    

GlideSystem - calDateDiff(String startDate, String endDate, Boolean numericValue)

Calculate the difference between two dates using the default calendar.

Calendars are now legacy. If Schedules are being used, see the topic Calculate Duration Given a Schedule.

Table 29. Parameters
Name Type Description
startDate String The starting date to compare in the current user's date format.
endDate String The ending date to compare in the current user's date format.
numericValue Boolean If true, the return value will be formatted in number of seconds; if false the return value will be formatted ddd hh:mm:ss.
Table 30. Returns
Type Description
String If the numericValue parameter is true, returns the difference between the two dates as an integer number of seconds; if false, returns the difference between the two dates in the format ddd hh:mm:ss.


      
    

GlideSystem - dateDiff(String startDate, String endDate, Boolean numericValue)

Calculates the difference between two dates.

This method expects the earlier date as the first parameter and the later date as the second parameter; otherwise, the method returns the difference as a negative value. Use getDisplayValue() to convert the strings to the expected format.

This method expects parameters in the user/system date time format, which may not be the same as the internal format. Using parameters in formats other than the user/system date time format may return invalid results.

If you are working with GlideDateTime objects use the GlideDateTime subtract() method instead of dateDiff().

Table 31. Parameters
Name Type Description
startDate String The starting date to compare in the current user's date format.
endDate String The ending date to compare in the current user's date format.
numericValue Boolean If true, the return value will be formatted in number of seconds; if false the return value will be formatted ddd hh:mm:ss.
Table 32. Returns
Type Description
String If the numericValue parameter is true, returns the difference between the two dates as an integer number of seconds; if false, returns the difference between the two dates in the format ddd hh:mm:ss.

// Given two date/times as DateTime objects
// Set the values this way to ensure a consistent input time
var date1 = new GlideDateTime();
var date2 = new GlideDateTime();
date1.setDisplayValueInternal('2014-01-01 12:00:00');
date2.setDisplayValueInternal('2014-01-01 13:00:00');
 
// Determine the difference as number of seconds (returns a string)
// Use getDisplayValue() to convert the string to the format expected by dateDiff()
var diffSeconds = gs.dateDiff(date1.getDisplayValue(), date2.getDisplayValue(), true);
 
// JavaScript will coerce diffSeconds from a string to a number
// since diffSeconds is being compared to a number
var msg = (diffSeconds <= 0) ? ' is on or after ' : ' is before ';
gs.print(date1.getDisplayValue() + msg + date2.getDisplayValue())

GlideSystem - dateGenerate(String date, String range)

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

Table 33. Parameters
Name Type Description
date String Format: yyy-mm-dd
range String Start, end, or a time in the 24 hour format hh:mm:ss.
Table 34. 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 equivalent

To use the dateGenerate() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - dateGenerate(String date, String range).


      
    

GlideSystem - daysAgo(Number days)

Returns a date and time for a certain number of days ago.

Table 35. Parameters
Name Type Description
days Number An integer number of days
Table 36. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped equivalent

To use the daysAgo() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - daysAgo(Number days).

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();
}

GlideSystem - daysAgoEnd(Number days)

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

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

Scoped equivalent

To use the daysAgoEnd() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - daysAgoEnd(Number days).


      
    

GlideSystem - daysAgoLocal(Number days)

Returns the date and time of the beginning of the day for the specified number of days ago. The returned date and time reflect the time zone of the current session (local time).

Table 39. Parameters
Name Type Description
days Number Number of days ago
Table 40. Returns
Type Description
String Local date and time for the beginning of the day in the user-defined date time format. If the date time format is not modified from its initial value the format is yyyy-mm-dd hh:mm:ss.

if (due_in == "1 Day") {
  dd = gs.daysAgoLocal(-1);
}
if (due_in == "1 Week") {
  dd = gs.daysAgoLocal(-7);
}

GlideSystem - daysAgoStart(Number days)

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

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

Scoped equivalent

To use the daysAgoStart() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - daysAgoStart(Number days).

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

GlideSystem - endOfLastMonth()

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

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

Scoped equivalent

To use the endOfLastMonth() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - endOfLastMonth().


      
    

GlideSystem - endOfLastWeek()

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

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

Scoped equivalent

To use the endOfLastWeek() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - endOfLastWeek().


      
    

GlideSystem - endOfLastYear()

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

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

Scoped equivalent

To use the endOfLastYear() method in a scoped application, use the corresponding scoped method:Scoped GlideSystem - endOfLastYear().


      
    

GlideSystem - endOfNextMonth()

Returns the date and time for the end of next 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 equivalent

To use the endOfNextMonth() method in a scoped application, use the corresponding scoped method:Scoped GlideSystem - endOfNextMonth().


      
    

GlideSystem - endOfNextWeek()

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

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

Scoped equivalent

To implement the endOfNextWeek() functionality in a scoped application, first create a script include that returns the GlideDateTime that is set to the end of next week. For example:

var DTUtil = Class.create();
DTUtil.prototype = {
    initialize: function() {
    },
endOfNextWeek: function() {
var nextWeek = gs.endOfWeek();
gs.debug("End of week: {0}", nextWeek);
 
var gdt = new GlideDateTime();
gdt.setDisplayValueInternal(nextWeek);
gdt.addWeeksUTC(1);
 
gs.debug("End of next week: {0}", gdt.getDisplayValue());
return gdt;
},
 
    type: 'DTUtil'
};

This script include is available to all application scopes and is client-callable.

Next, use Scripts - Background to update your sys_report filter to use this script include. To update the filter, you need the sys_id of your sys_report. You should also note the scope to which you added the script include and use that scope name in the setValue name of your script. For example, assuming your report sys_id is "4dc5e0e7c3103200f7d1ca3adfba8f52" and the scope of the application is sn_scope:

var gr = new GlideRecord('sys_report');
gr.get('4dc5e0e7c3103200f7d1ca3adfba8f52');
gr.setValue('filter', 'sys_created_on<=javascript:new sn_scope.DTUtil().endOfNextWeek()^EQ^GROUPBYsys_created_on');
gr.update();

This code runs in the same scope as the report.


      
    

GlideSystem - endOfNextYear()

Returns the date and time for the end of next year 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 equivalent

To use the endOfNextYear() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - endOfNextYear().


      
    

GlideSystem - endOfThisMonth()

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

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

Scoped equivalent

To use the endOfThisMonth() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - endOfThisMonth().


      
    

GlideSystem - endOfThisQuarter()

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

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

Scoped equivalent

To use the endOfThisQuarter() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - endOfThisQuarter().


      
    

GlideSystem - endOfThisWeek()

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

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

Scoped equivalent

To use the endOfThisWeek() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - endOfThisWeek().


      
    

GlideSystem - endOfThisYear()

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

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

Scoped equivalent

To use the endOfThisYear() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - endOfThisYear().


      
    

GlideSystem - endOfToday()

Gets the date and time for the end of today in GMT.

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


      
    

GlideSystem - endOfYesterday()

Gets the date and time for the end of yesterday in GMT.

Table 65. Parameters
Name Type Description
None
Table 66. Returns
Type Description
String GMT in the format (yyyy-mm-dd huh:mm:ss).


      
    

GlideSystem - eventQueue(String name, Object glideRecord, String parm1, String parm2, String queueName)

Queues an event for the event manager.

Table 67. Parameters
Name Type Description
name String Name of the event being queued.
glideRecord 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 68. Returns
Type Description
void

Scoped equivalent

To use the eventQueue() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - eventQueue(String name, Object instance, String parm1, String parm2, String parm3).

if (current.operation() != 'insert' && current.comments.changes()) {
    gs.eventQueue("incident.commented", current, gs.getUserID(), gs.getUserName());
}

GlideSystem - flushMessages()

Clears session messages saved using addErrorMessage() or addInfoMessage().

Session messages are shown at the top of the form. In client side scripts, use g_form.clearMessages() to remove session messages.

Table 69. Parameters
Name Type Description
None
Table 70. Returns
Type Description
void

gs.flushMessages();

GlideSystem - getAvatar()

Returns the file path to the user's avatar.

Table 71. Parameters
Name Type Description
None
Table 72. Returns
Type Description
String The file path to the user's avatar.

var avatarFile = gs.getUser().getAvatar();        
gs.addInfoMessage('User avatar ID: ' + avatarFile);

Output:

User avatar ID: c148e1d13741310042106710ce41f149.iix?t=small

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

Scoped equivalent

To use the getCurrentScopeName() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - getCurrentScopeName().

gs.getCurrentScopeName();

GlideSystem - getDisplayColumn(String tableName)

Gets the display column for the table.

Table 75. Parameters
Name Type Description
tableName String Name of the table from which to get the display column name.
Table 76. Returns
Type Description
String Display column name

// Return the sys_id value for a given table and its display value
function GetIDValue(table, displayValue) { 
    var rec = new GlideRecord(table);
    var dn = gs.getDisplayColumn(table);
    if (rec.get(dn, displayValue))
        return rec.sys_id;
    else
        return null;
}

GlideSystem - getDisplayValueFor(String tableName, String recordID, String fieldName)

Returns the display value for a specified field on a record.

Table 77. Parameters
Name Type Description
tableName String Name of the table
recordID String sysid for the record
fieldName String Name of the field
Table 78. Returns
Type Description
String Display value for the field


      
    

GlideSystem - getErrorMessages()

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

Table 79. Parameters
Name Type Description
None
Table 80. Returns
Type Description
String List of error messages

Scoped equivalent

To use the getErrorMessages() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - getErrorMessages().


      
    

GlideSystem - getEscapedProperty(String key, Object substituteObject)

Gets the property and escapes it for XML parsing.

Table 81. Parameters
Name Type Description
key String Key for the property whose value should be returned.
substituteObject Object Object to be returned if the property is not found.
Table 82. Returns
Type Description
String The property, or the substituteObject if the property is not found.


      
    

GlideSystem - getImpersonatingUserDisplayName()

Returns the display name of the impersonating user.

Table 83. Parameters
Name Type Description
None
Table 84. Returns
Type Description
String The display name of the impersonating user


      
    

GlideSystem - getImpersonatingUserName()

Returns the name of the impersonating user or null if not impersonating.

Table 85. Parameters
Name Type Description
None
Table 86. Returns
Type Description
String Name of impersonating user


      
    

GlideSystem - getInfoMessages()

Gets the list of info messages for the session that were added by addInfoMessage().

Table 87. Parameters
Name Type Description
None
Table 88. Returns
Type Description
String List of info messages


      
    

GlideSystem - getInitials()

Returns the user's initials.

Table 89. Parameters
Name Type Description
None
Table 90. Returns
Type Description
String The user's initials.

var userInitials = gs.getUser().getInitials();        
gs.addInfoMessage('User initials: ' + userInitials);

Output:

User initials: SA

GlideSystem - getMessage(String messageID, Object args)

Retrieves translated messages to display in the UI.

If the specified string exists in the database for the current language, then the translated message is returned. If the specified string does not exist for the current language, then the English version of the string is returned. If the string does not exist at all in the database, then the ID itself is returned.

If the UI message has a tick ('), there may be issues with the message in the script; to escape the ticks ('), use getMessageS(String, Object).

Table 91. Parameters
Name Type Description
MessageID String The ID of the message.
args Object (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 92. Returns
Type Description
String The UI message

Scoped equivalent

To use the getMessage() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - getMessage(String id, Array args).

var my_message = '${gs.getMessage("This is a message.")}'; 
alert(my_message);

Using the optional parameter:

gs.getMessage('"{0}" is not a Client Callable Script Include','BAR’);

Output:

"BAR" is not a Client Callable Script Include

GlideSystem - getMessages(String type)

Gets the list of messages of the specified type for the session that were added by addMessage().

Table 93. Parameters
Name Type Description
type String The type of message
Table 94. Returns
Type Description
void


      
    

GlideSystem - getMessageS(String messageID, Object args)

Retrieves translated messages to display in the UI and escapes all ticks (').

If the specified string exists in the database for the current language, then the translated message is returned. If the specified string does not exist for the current language, then the English version of the string is returned. If the string does not exist at all in the database, then the ID itself is returned. Useful if you are inserting into a JavaScript expression from Jelly.

Table 95. Parameters
Name Type Description
MessageID String The ID of the message.
args Object (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 96. Returns
Type Description
String The message with ticks escaped.
/*
"I love France" translates to "J'aime la France" in French.
Rendering this without escaping the tick in "J'aime" would break Jelly, because 
the tick would prematurely end the variable assignment, and everything that 
follows (aime la France') would be a jelly syntax error.
*/
var my_message = '${gs.getMessageS("I love France")}'; 
alert(my_message);

Output:

J'aime la France

GlideSystem - getNodeValue(Object obj, Number index)

Gets the node value for specified index.

Table 97. Parameters
Name Type Description
obj Object Object to examine
index Number Index from which to get the node value
Table 98. Returns
Type Description
Object The node's value


      
    

GlideSystem - getNodeName(Object obj, Number index)

Returns the node name for specified index.

Table 99. Parameters
Name Type Description
obj Object Object to examine
index Number Index from which to get the node name
Table 100. Returns
Type Description
String The node's name


      
    

GlideSystem - getPreference(String key, Object default)

Gets a user preference.

Table 101. Parameters
Name Type Description
key String The key for the preference
default Object The default value
Table 102. Returns
Type Description
String The preference. If no preference, returns the specified default value.


      
    

GlideSystem - getProperty(String key, Object alt)

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

Table 103. 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 104. Returns
Type Description
String The value of the Glide property, or the alternate object defined above.

Scoped equivalent

To use the getProperty() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - getProperty(String key, Object alt).

//Check for attachments and add link if there are any
  var attachment_link = '';
  var rec = new GlideRecord('sc_req_item');
  rec.addQuery('sys_id', current.request_item);
  rec.query();
  if(rec.next()){
    if(rec.hasAttachments()){
      attachment_link = gs.getProperty('glide.servlet.uri') + rec.getLink();
    }    
  }

GlideSystem - getScriptError(String script)

Returns the script error found in the specified script, if there is one.

The script is not executed by this function, only checked for syntax errors.

Table 105. Parameters
Name Type Description
script String The script to check for errors.
Table 106. Returns
Type Description
String The error message, or null if there is no error.


      
    

GlideSystem - getSession()

Returns a GlideSession object.

Table 107. Parameters
Name Type Description
None
Table 108. Returns
Type Description
GlideSession Object A GlideSession object for the current session

Scoped equivalent

To use the getSession() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - getSession().

var session = gs.getSession();

GlideSystem - getSessionID()

Returns the GlideSession Session ID.

Table 109. Parameters
Name Type Description
None
Table 110. Returns
Type Description
String The session ID

Scoped equivalent

To use the getSessionID() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - getSessionID().


      
    

GlideSystem - getStyle(String tableName, String fieldName, String fieldValue)

Returns the style defined for the table, field and value.

Table 111. Parameters
Name Type Description
tableName String The table name
fieldName String The field name
fieldValue String The field value
Table 112. Returns
Type Description
String The style


      
    

GlideSystem - getTrivialMessages()

Gets the list of error messages for the session that were added with the trivial flag.

Table 113. Parameters
Name Type Description
None
Table 114. Returns
Type Description
String List of messages


      
    

GlideSystem - getUser()

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

Table 115. Parameters
Name Type Description
None
Table 116. Returns
Type Description
GlideUser A reference to a user object for the current user

Scoped equivalent

To use the getUser() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - getUser().

var myUserObject = gs.getUser()

GlideSystem - getUserDisplayName()

Returns the name field of the current user (e.g. John Smith, as opposed to smith).

Table 117. Parameters
Name Type Description
None
Table 118. Returns
Type Description
String The user's display name

Scoped equivalent

To use the getUserDisplayName() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - getUserDisplayName().

gs.getUserDisplayName();

GlideSystem - getUserID()

Returns the sys_id of the current user.

Table 119. Parameters
Name Type Description
None
Table 120. Returns
Type Description
String The sys_id of the current user.

Scoped equivalent

To use the getUserID() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - getUserID().

if (current.operation() != 'insert' && current.comments.changes()) {
    gs.eventQueue("incident.commented", current, gs.getUserID(), gs.getUserName());
}

GlideSystem - getUserName()

Returns the username of the current user (e.g., jsmith).

Table 121. Parameters
Name Type Description
None
Table 122. Returns
Type Description
String Username of the current user

Scoped equivalent

To use the getUserName() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - getUserName().

//Add a comment when closing
    current.comments = "Closed by " + gs.getUserName() + " at " + gs.nowDateTime();
    gs.addInfoMessage("Close comment added");
}

GlideSystem - getUserNameByUserID(String sys_id)

Gets the username based on a user ID.

Table 123. Parameters
Name Type Description
sys_id String A sys_id for a user
Table 124. Returns
Type Description
String The username


      
    

GlideSystem - getXMLNodeList(String xml)

Constructs an Array of all the nodes and values in an XML document.

Table 125. Parameters
Name Type Description
xml String The XML document to parse
Table 126. Returns
Type Description
Array list List of names and values


      
    

GlideSystem - getXMLText(String xml, String xpathQuery)

Gets the XML text for the first node in the XML string that matches the XPath query.

Table 127. Parameters
Name Type Description
xml String An XML string
xpathQuery String The XPath query to match
Table 128. Returns
Type Description
String The XML node


      
    

GlideSystem - hasRole(String roleName)

Determines if the current user has the specified role.

Table 129. Parameters
Name Type Description
roleName String The role to check
Table 130. Returns
Type Description
Boolean True if the user has the role, false otherwise. Also returns true if the user has the administrator role.

Scoped equivalent

To use the hasRole() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - hasRole(Object 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
}

GlideSystem - hasRoleInGroup(Object roleName, Object group)

Determines if the current user has the specified role within a specified group.

Table 131. Parameters
Name Type Description
roleName Object Name of the role
group Object sys_id of the group to check for the specified role
Table 132. Returns
Type Description
Boolean Returns true when the following conditions are met, otherwise returns false.
  • The logged-in user is assigned to the specified the role.
  • The granted by field on the user role record is set to the specified group.
  • The inherited field on the user role record is false.

var group = new GlideRecord('sys_user_group');
group.addQuery('name', 'GROUP_NAME');
group.setLimit(1);
group.query();
if (group.next()) {
   if (gs.hasRoleInGroup('role_name', group)) {
      gs.print('User has role in group');  
   } else {
      gs.print('User does NOT have role in group');
   }  
}

GlideSystem - hoursAgo(Number hours)

Returns a date and time for a certain number of hours ago.

Table 133. Parameters
Name Type Description
hours Number An integer number of hours
Table 134. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped equivalent

To use the hoursAgo() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - hoursAgo(Number hours).

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);
  }
 }
}

GlideSystem - hoursAgoEnd(Number hours)

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

Table 135. Parameters
Name Type Description
hours Number An integer number of hours
Table 136. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped equivalent

To use the hoursAgoEnd() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - hoursAgoEnd(Number hours).


      
    

GlideSystem - hoursAgoStart(Number hours)

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

Table 137. Parameters
Name Type Description
hours Number An integer number of hours
Table 138. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped equivalent

To use the hoursAgoStart() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - hoursAgoStart(Number hours).


      
    

GlideSystem - isFirstDayOfMonth(Object date)

Checks whether the date is the first day of the month.

Table 139. Parameters
Name Type Description
date Object date object
Table 140. Returns
Type Description
Boolean True if the date is the first day of the month, false otherwise.


      
    

GlideSystem - isFirstDayOfWeek(Object date)

Checks whether the date is the first day of the week. This uses the ISO standard of Monday being the first day of the week.

Table 141. Parameters
Name Type Description
date Object date object
Table 142. Returns
Type Description
Boolean True if the date is the first day of the month, false otherwise.


      
    

GlideSystem - isFirstDayOfYear(Object date)

Checks whether the date is the first day of the year.

Table 143. Parameters
Name Type Description
date Object date object
Table 144. Returns
Type Description
Boolean True if the date is the first day of the year, false otherwise.


      
    

GlideSystem - isInteractive()

Checks if the current session is interactive.

An example of an interactive session is when a user logs in using the log-in screen. An example of a non-interactive session is using a SOAP request to retrieve data.

Table 145. Parameters
Name Type Description
None
Table 146. Returns
Type Description
Boolean True if the session is interactive.

Scoped equivalent

To use the isInteractive() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - isInteractive().

if (!gs.hasRole('admin') && gs.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);
   }
}

GlideSystem - isLastDayofMonth(Object date)

Checks whether the date is the last day of the month.

Table 147. Parameters
Name Type Description
date Object date object
Table 148. Returns
Type Description
Boolean True if the date is the last day of the month, false otherwise. Uses the ISO standard of Sunday being the last day of the week.


      
    

GlideSystem - isLastDayOfWeek(Object date)

Checks whether the date is the last day of the week.

Table 149. Parameters
Name Type Description
date Object date object
Table 150. Returns
Type Description
Boolean True if date is the last day of the week, false otherwise.


      
    

GlideSystem - isLastDayOfYear(Object date)

Checks whether the date is the last day of the year.

Table 151. Parameters
Name Type Description
date Object date object
Table 152. Returns
Type Description
Boolean True if date is the last day of the year, false otherwise.


      
    

GlideSystem - isLoggedIn()

Determines if the current user is currently logged in.

Table 153. Parameters
Name Type Description
None
Table 154. Returns
Type Description
Boolean True if the current user is logged in, false otherwise.

Scoped equivalent

To use the isLoggedIn() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - isLoggedIn().


      
    

GlideSystem - isMobile()

Determines if a request comes from a mobile device.

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

Table 155. Parameters
Name Type Description
None
Table 156. Returns
Type Description
Boolean True if the request comes from a mobile device; otherwise, false

Scoped equivalent

To use the isMobile() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - isMobile().

if (gs.isMobile())
  gs.info("submitted from mobile UI");
 else 
   gs.info("NOT submitted from mobile UI");

GlideSystem - lastWeek()

Date and time one week ago in GMT.

Table 157. Parameters
Name Type Description
None
Table 158. Returns
Type Description
String The date and time one week ago, in the format yyyy-mm-dd hh:mm:ss.


      
    

GlideSystem - log(String message, String source)

Logs a message to the system log and saves it to the syslog table.

Table 159. Parameters
Name Type Description
message String The message to log.
source String (optional) The source of the message.
Table 160. Returns
Type Description
void

var count = new GlideAggregate('incident');
count.addQuery('active', 'true');
count.addAggregate('COUNT', 'category');
count.query();   
while (count.next()) {
   var category = count.category;
   var categoryCount = count.getAggregate('COUNT', 'category');
   gs.log("The are currently " + categoryCount + " incidents with a category of " + category, "Incident Counter");
}

GlideSystem - logError(String message, String source)

Logs an error to the system log and saves it to the syslog table.

Table 161. Parameters
Name Type Description
message String The message to log.
source String (optional) The source of the message
Table 162. Returns
Type Description
void


      
    

GlideSystem - logWarning(String message, String source)

Logs a warning to the system log and saves it to the syslog table.

Table 163. Parameters
Name Type Description
message String The message to log.
source String (optional) The source of the message
Table 164. Returns
Type Description
void


      
    

GlideSystem - minutesAgo(Number minutes)

Returns a date and time for a certain number of minutes ago

Table 165. Parameters
Name Type Description
minutes Number An integer number of minutes
Table 166. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

/
// Check to see if the user has failed to login too many times
// when the limit is reached, lock the user out of the system
//
  //Check failed logins in the last 15 minutes
  var gr = new GlideRecord('sysevent');
  gr.addQuery('name', 'login.failed');
  gr.addQuery('parm1', event.parm1.toString());
  gr.addQuery('sys_created_on','>=', gs.minutesAgo(15));
  gr.query();
  var rowCount = gr.getRowCount();
  if(rowCount >= 5){
      var gr = new GlideRecord("sys_user");
      gr.addQuery("user_name", event.parm1.toString());
      gr.query();
      if (gr.next()) {
           gr.locked_out = true;
           gr.update();
           gs.log("User " + event.parm1 + " locked out due to too many invalid login attempts");
      }
  }

GlideSystem - minutesAgoEnd(Number minutes)

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

Table 167. Parameters
Name Type Description
minutes Number An integer number of minutes
Table 168. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped equivalent

To use the minutesAgoEnd() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - minutesAgoEnd(Number minutes).


      
    

GlideSystem - minutesAgoStart(Number minutes)

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

Table 169. Parameters
Name Type Description
minutes Number An integer number of minutes
Table 170. Returns
Type Description
String GMT in the format yyyy-mm-dd hh:mm:ss

Scoped equivalent

To use the minutesAgoStart() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - minutesAgoStart(Number minutes).


      
    

GlideSystem - monthsAgo(Number months)

Returns a date and time for a certain number of months ago.

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

Scoped equivalent

To use the monthsAgo() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - monthsAgo(Number months).


      
    

GlideSystem - monthsAgoEnd(Number months)

Gets a date and time for the last day of the month a certain number of months ago.

Table 173. Parameters
Name Type Description
months Number An integer number of months
Table 174. Returns
Type Description
String GMT end of the month the specified number of months ago, in the format yyyy-mm-dd hh:mm:ss.


      
    

GlideSystem - monthsAgoStart(Number months)

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

Table 175. Parameters
Name Type Description
months Number An integer number of months
Table 176. 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 equivalent

To use the monthsAgoStart() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - monthsAgoStart(Number months).


      
    

GlideSystem - nil(Object obj)

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

Table 177. Parameters
Name Type Description
obj Object The object to be checked.
Table 178. Returns
Type Description
Boolean True if null or empty string; otherwise, false.

Scoped equivalent

To use the nil() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - nil(Object o).

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);
  }
}

GlideSystem - now()

Returns the current date in UTC.

Table 179. Parameters
Name Type Description
None
Table 180. Returns
Type Description
String The current date in the user-defined format, in UTC.

// When the user password changes then set the u_password_last_reset field
// to now so we know when to force another update
 
var gr = new GlideRecord("sys_user");
if (gr.get(event.parm1.toString())) {
    // Do something based on the Password Changing
    gs.log("The user password changed so do something else...");
    gr.u_password_last_reset = gs.now();
    gr.update();
}

GlideSystem - nowNoTZ()

Gets the current date and time in UTC format.

Table 181. Parameters
Name Type Description
None
Table 182. Returns
Type Description
String The current UTC date time

// When the user password changes then set the u_password_last_reset field
// to now so we know when to force another update
 
var gr = new GlideRecord("sys_user");
if (gr.get(event.parm1.toString())) {
    // Do something based on the Password Changing
    gs.log("The user password changed so do something else...");
    gr.u_password_last_reset = gs.nowNoTZ();
    gr.update();
}

GlideSystem - nowDateTime()

Gets the current date and time in the user-defined format.

Table 183. Parameters
Name Type Description
None
Table 184. Returns
Type Description
String The current date and time in the user-defined format.

current.u_target_date = gs.nowDateTime();

When setting a variable in a workflow script to the current date and time, use the setDisplayValue() method. The following script sets the workflow variable end_date to the current date and time.

current.variables.end_date.setDisplayValue(gs.nowDateTime());

GlideSystem - print(String message)

Writes a message to the system log.

This method does not write the message to the syslog table unless debug has been activated.

Table 185. Parameters
Name Type Description
message String The message to log
Table 186. Returns
Type Description
void

var rec = new GlideRecord('incident');
rec.addQuery('active',false);
rec.query();
while (rec.next()) { 
 gs.print('Inactive incident ' + rec.number + ' deleted');
 rec.deleteRecord();
}

GlideSystem - quartersAgo(Number quarters)

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

Table 187. Parameters
Name Type Description
quarters Number An integer number of quarters
Table 188. Returns
Type Description
String GMT beginning of the quarter that was the specified number of quarters ago, in the format yyyy-mm-dd hh:mm:ss.


      
    

GlideSystem - quartersAgoEnd(Number quarters)

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

Table 189. Parameters
Name Type Description
quarters Number An integer number of quarters
Table 190. 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 equivalent

To use the quartersAgoEnd() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - quartersAgoEnd(Number quarters).


      
    

GlideSystem - quartersAgoStart(Number quarters)

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

Table 191. Parameters
Name Type Description
quarters Number An integer number of quarters
Table 192. 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 equivalent

To use the quartersAgoStart() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - quartersAgoStart(Number quarters).


      
    

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

Sets the specified key to the specified value.

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 193. 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 194. Returns
Type Description
void

Scoped equivalent

To use the setProperty() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - setProperty(String key, String value, String description).

gs.setProperty("glide.foo","bar","foo");
gs.info(gs.getProperty("glide.foo"));

Output: bar

GlideSystem - setRedirect(Object URI)

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

Table 195. Parameters
Name Type Description
URI Object URI to set as the redirect
Table 196. Returns
Type Description
void

Scoped equivalent

To use the setRedirect() method in a scoped application, use the corresponding scoped method:Scoped GlideSystem - setRedirect(Object o).

This example redirects the user to a particular catalog item, and passes along the current email as a parameter.

gs.setRedirect("com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=d41ce5bac611227a0167f4bf8109bf70&sysparm_user=" 
+ current.sys_id + "&sysparm_email=" + current.email)

GlideSystem - setReturn(Object URI)

Sets the return URI for this transaction. This determines what page the user will be directed to when they return from the next form.

Table 197. Parameters
Name Type Description
URI Object URI to set as the return location.
Table 198. Returns
Type Description
void

This example ensures that the user will be returned to the current page when they are done with the next one.

gs.setReturn (current.getLink(true));

GlideSystem - tableExists(String tableName)

Determines if a database table exists.

Table 199. Parameters
Name Type Description
tableName String Name of the table
Table 200. Returns
Type Description
Boolean True if the table exists, false otherwise.

Scoped equivalent

To use the tableExists() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - tableExists(String name).


      
    

GlideSystem - userID()

Returns the sys_id of the user associated with this session. Use getUserID() instead.

Table 201. Parameters
Name Type Description
None
Table 202. Returns
Type Description
String sys_id of the current user


      
    

GlideSystem - workflowFlush(Object glideRecord)

Deletes all existing workflow operations for the specified GlideRecord.

Table 203. Parameters
Name Type Description
glideRecord Object The GlideRecord
Table 204. Returns
Type Description
void


      
    

GlideSystem - yearsAgo(Number years)

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

Table 205. Parameters
Name Type Description
years Number An integer number of years
Table 206. 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.


      
    

GlideSystem - yesterday()

Returns yesterday's time (24 hours ago).

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

Scoped equivalent

To use the yesterday() method in a scoped application, use the corresponding scoped method: Scoped GlideSystem - yesterday().