GlideSystem - Global

  • Release version: Xanadu
  • Updated August 1, 2024
  • 52 minutes to read
  • The GlideSystem API, which is referred to by the variable name gs in any server-side JavaScript, provides a number of convenient methods to get information about the system, the current logged in user, and date/time information.

    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
    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]

    Scoped equivalent

    To use the addErrorMessage() method in a scoped application, use the corresponding scoped method: addErrorMessage().

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

    Scoped equivalent

    To use the addInfoMessage() method in a scoped application, use the corresponding scoped method: addInfoMessage().

    GlideSystem - addMessage(String type, Object message)

    Adds a message for the current session.

    Table 5. Parameters
    Name Type Description
    type String Type of message, such as error or info.
    message Object Message to add to the current session.
    Table 6. Returns
    Type Description
    void

    GlideSystem - beginningOfLastMonth()

    Gets 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 The GMT beginning of last month, in the format yyyy-mm-dd hh:mm:ss.

    This example sets the date and time of the GlideDateTime object to the beginning of last month.

    var date = new GlideDate();
    date.setValue(gs.beginningOfLastMonth());
    var dateasint = date.toString().replace('-','');
    gs.print(dateasint);

    Scoped equivalent

    To use the beginningOfLastMonth() method in a scoped application, use the corresponding scoped method: 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.

    Format: yyyy-mm-dd hh:mm:ss

    This example sets the value of the current Glide date/time record to the beginning of last week.

    var gdt2 = new GlideDateTime(dt);
    gdt2.setValue(gs.beginningOfLastWeek());

    Scoped equivalent

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

    GlideSystem - beginningOfNextWeek()

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

    Table 11. Parameters
    Name Type Description
    None
    Table 12. Returns
    Type Description
    String GMT beginning of next week.

    Format: yyyy-mm-dd hh:mm:ss

    This example sets the value of the current Glide date/time record to the beginning of next week.

    var gdt2 = new GlideDateTime(dt);
    gdt2.setValue(gs.beginningOfNextWeek());

    Scoped equivalent

    To use the beginningOfNextWeek() method in a scoped application, use the corresponding scoped method: beginningOfNextWeek().

    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.

    Format: yyyy-mm-dd hh:mm:ss

    This example sets the value of the current Glide date/time record to the beginning of next month.

    var gdt2 = new GlideDateTime(dt);
    gdt2.setValue(gs.beginningOfNextMonth());

    Scoped equivalent

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

    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 The GMT beginning of next year, in the format yyyy-mm-dd hh:mm:ss.

    This example sets the value of the current Glide date/time record to the beginning of next year.

    var gdt2 = new GlideDateTime(dt);
    gdt2.setValue(gs.beginningOfNextYear());

    Scoped equivalent

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

    GlideSystem - beginningOfThisMonth()

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

    Table 17. Parameters
    Name Type Description
    None
    Table 18. Returns
    Type Description
    String GMT beginning of the current month.

    Format: yyyy-mm-dd hh:mm:ss

    This example sets the value of the current Glide date/time record to the beginning of this month.

    var gdt2 = new GlideDateTime(dt);
    gdt2.setValue(gs.beginningOfThisMonth());

    Scoped equivalent

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

    GlideSystem - beginningOfThisQuarter()

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

    Table 19. Parameters
    Name Type Description
    None
    Table 20. Returns
    Type Description
    String GMT beginning of the current quarter.

    Format: yyyy-mm-dd hh:mm:ss

    This example sets the value of the current Glide date/time record to the beginning of the current quarter.

    var gdt2 = new GlideDateTime(dt);
    gdt2.setValue(gs.beginningOfThisQuarter());

    Scoped equivalent

    To use the beginningOfThisQuarter() method in a scoped application, use the corresponding scoped method: 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 the current week.

    Format: yyyy-mm-dd hh:mm:ss

    This example sets the value of the current Glide date/time record to the beginning of the current week.

    var gdt2 = new GlideDateTime(dt);
    gdt2.setValue(gs.beginningOfThisWeek());

    Scoped equivalent

    To use the beginningOfThisWeek() method in a scoped application, use the corresponding scoped method: 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 the current year.

    Format: yyyy-mm-dd hh:mm:ss

    This example sets the value of the current Glide date/time record to the beginning of the current year.

    var gdt2 = new GlideDateTime(dt);
    gdt2.setValue(gs.beginningOfThisYear());

    Scoped equivalent

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

    GlideSystem - beginningOfToday()

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

    Table 25. Parameters
    Name Type Description
    None
    Table 26. Returns
    Type Description
    String GMT beginning of the current day.

    Format: yyyy-mm-dd hh:mm:ss

    This example sets the value of the current Glide date/time record to the beginning of the current day.

    var gdt2 = new GlideDateTime(dt);
    gdt2.setValue(gs.beginningOfToday());

    GlideSystem - beginningOfTomorrow()

    Retrieves the (UTC) beginning of tomorrow adjusted for the timezone of the current session.

    Table 27. Parameters
    Name Type Description
    None
    Table 28. Returns
    Type Description
    String GMT beginning of tomorrow.

    Format: yyyy-mm-dd hh:mm:ss

    var today = new GlideDateTime(gs.beginningOfTomorrow()).getNumericValue();

    GlideSystem - beginningOfYesterday()

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

    Table 29. Parameters
    Name Type Description
    None
    Table 30. Returns
    Type Description
    String The GMT beginning of yesterday, in the format yyyy-mm-dd hh:mm:ss.
    var start = new GlideDateTime();
    start.setValue(gs.beginningOfYesterday());

    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 'Calculate during a given schedule' section of the topic Scheduling script use cases.

    Table 31. Parameters
    Name Type Description
    startDate String Starting date to compare in the current user's date format.
    endDate String Ending date to compare in the current user's date format.
    numericValue Boolean Flag that indicates ther format of the returned time value.

    Valid values:

    • true: Return value is formatted in number of seconds
    • false: Return value is 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.

    var endDateTime = gs.nowDateTime();
    gs.print('--- Total records: ' + countRecordsTotal);
    gs.print('--- End time: ' + endDateTime);
    gs.print('Time diff: ' + gs.calDateDiff(startDateTime, endDateTime));

    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 33. 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 34. 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 35. Parameters
    Name Type Description
    date String Date to generate in GMT.

    Format: yyyy-mm-dd

    range String Start, end, or a time.

    Format: 24-hour hh:mm:ss

    Table 36. Returns
    Type Description
    String Generated date and time.

    If the 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.

    Format: yyyy-mm-dd hh:mm:ss

    This example shows using dateGenerate() to set the start date when querying records in the Incident table.

    var tableData = new GlideRecord('incident');
    tableData.addEncodedQuery("sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-07','00:00:00')@javascript:gs.daysAgoEnd(0)^priority=1^severityIN1,2");
    tableData.query();
    gs.info("Count: " + tableData.getRowCount());

    Output:

    Count: 7

    Scoped equivalent

    To use the dateGenerate() method in a scoped application, use the corresponding scoped method: dateGenerate().

    GlideSystem - daysAgo(Number days)

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

    Table 37. Parameters
    Name Type Description
    days Number Number of days
    Table 38. Returns
    Type Description
    String GMT of the specified number of days ago.

    Format: yyyy-mm-dd hh:mm:ss.

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

    Scoped equivalent

    To use the daysAgo() method in a scoped application, use the corresponding scoped method: daysAgo().

    GlideSystem - daysAgoEnd(Number days)

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

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

    This example shows using daysAgoEnd() to set the end date when querying records in the Incident table.

    var tableData = new GlideRecord('incident');
    tableData.addEncodedQuery("sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-07','00:00:00')@javascript:gs.daysAgoEnd(0)^priority=1^severityIN1,2");
    tableData.query();
    gs.addInfoMessage("Count: " +tableData.getRowCount());

    Scoped equivalent

    To use the daysAgoEnd() method in a scoped application, use the corresponding scoped method: daysAgoEnd().

    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 41. Parameters
    Name Type Description
    days Number Number of days ago
    Table 42. 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 43. Parameters
    Name Type Description
    days String Integer number of days
    Table 44. Returns
    Type Description
    String GMT start of the day in the format yyyy-mm-dd hh:mm:ss
    var now_GR = new GlideRecord('sysapproval_approver');
    now_GR.addQuery('state', 'requested');
    now_GR.addQuery('sys_updated_on', '<', gs.daysAgoStart(5));
    now_GR.query();

    Scoped equivalent

    To use the daysAgoStart() method in a scoped application, use the corresponding scoped method: daysAgoStart().

    GlideSystem - endOfLastMonth()

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

    Table 45. Parameters
    Name Type Description
    None
    Table 46. Returns
    Type Description
    String GMT of the end of last month.

    Format: yyyy-mm-dd hh:mm:ss

    This example shows how to query a report record from the last day of last month.

    var month = gs.endOfLastMonth();
    var monthd = new GlideDateTime(month);
    monthd.addDays(-1);
    
    var queueLast = new GlideRecord('u_amazon_connect_phone_metrics');
    queueMtd.addQuery('u_queue_name',queueNames[i]);
    queueMtd.addEncodedQuery('u_time_range=MTD');
    queueMtd.addEncodedQuery('u_report_date'+ monthd);
    queueMtd.orderByDesc('u_report_date');
            
    queueMtd.query();
    
    if(queueMtd.next()){
      gs.info(queueMtd.u_report_date);
    } 

    Scoped equivalent

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

    GlideSystem - endOfLastWeek()

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

    Table 47. Parameters
    Name Type Description
    None
    Table 48. Returns
    Type Description
    String GMT end of last week.

    Format: yyyy-mm-dd hh:mm:ss

    This example shows how to query records opened on the last week of the previous month.

    var inc = new GlideRecord('incident');
    inc.addQuery('active=true^priority=1^opened_atONLast month@javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth()^opened_atONLast week@javascript:gs.beginningOfLastWeek()@javascript:gs.endOfLastWeek()');
    inc.query();
    while(inc.next())
     {
       gs.addInfoMessage(inc.getRowCount());
     }

    Scoped equivalent

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

    GlideSystem - endOfLastYear()

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

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

    This example shows how to query records created for all records created in the last year.

    var inc = new GlideRecord('incident');
    inc.addEncodedQuery('sys_created_onONLast year@javascript:gs.beginningOfLastYear()@javascript:gs.endOfLastYear()');
    inc.query();
    while(inc.next()){
      inc.assignment_group = "d625dccec0a8016700a222a0f7900d06";
      inc.update();
    }

    Scoped equivalent

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

    GlideSystem - endOfNextMonth()

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

    Table 51. Parameters
    Name Type Description
    None
    Table 52. Returns
    Type Description
    String GMT data and time.

    Format yyyy-mm-dd hh:mm:ss

    This example shows how to query KB knowledge records created since the beginning of today until the end of next month.

    var query = "kb_knowledge_base=e81c9a0ddbc15810c38f0763b99619c1^ORkb_knowledge_base=21302e89db055810c38f0763b99619cc^valid_toBETWEENjavascript:gs.beginningOfToday()@javascript:gs.endOfNextMonth()^ORworkflow_state=pending_retirement^latest=true";
    var rec = new GlideRecord('kb_knowledge');
    rec.addEncodedQuery(query);
    rec.addQuery('author', current.author);
    rec.query();
    while (rec.next()) {
      var Kbtitle = rec.getValue('short_description');
      articles.push(rec.number.toString()+ '' + Kbtitle);
      template.print('Click here to view record<a href="https://give urs instance url here/nav_to.do?uri=kb_knowledge.do?sys_id=' + rec.sys_id + '">' + rec.number + '</a>');
    }
    var articlesList = "<ul>";
    for (i = 0; i <= articles.length-1; i++) {
      articlesList = articlesList + "<li>" + articles[i] + "</li>";
    }
    articlesList = articlesList + "</ul>";

    Scoped equivalent

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

    GlideSystem - endOfNextWeek()

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

    Table 53. Parameters
    Name Type Description
    None
    Table 54. Returns
    Type Description
    String GMT date and time for the end of next week.

    Format yyyy-mm-dd hh:mm:ss

    This example shows how to use endOfNextWeek() in a query to obtain all visitors in the past week.

    var title = 'Visitors arriving this Week';
    var visitorQuery = 'active=true^category=visitor_request^u_my_start_dateONThis week@javascript:gs.beginningOfThisWeek()@javascript:gs.endOfNextWeek()';

    Scoped equivalent

    To use the endOfNextWeek() method in a scoped application, use the corresponding scoped method: endOfNextWeek().

    GlideSystem - endOfNextYear()

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

    Table 55. Parameters
    Name Type Description
    None
    Table 56. Returns
    Type Description
    String GMT date and time for the end of next year.

    Format: yyyy-mm-dd hh:mm:ss

    This example shows how to use endOfNextYear() to set the GlideDateTime object to the end of next year.

    setEndDate : function(dt) {
      var gdt2 = new GlideDateTime(dt);
      gdt2.setValue(gs.endOfNextYear());
    }

    Scoped equivalent

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

    GlideSystem - endOfThisMonth()

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

    Table 57. Parameters
    Name Type Description
    None
    Table 58. Returns
    Type Description
    String GMT date and time for the end of this month.

    Format yyyy-mm-dd hh:mm:ss

    This example shows how to use endOfThisMonth() to set the GlideDateTime object to the end of the current month.

    setEndDate : function(dt) {
      var gdt2 = new GlideDateTime(dt);
      gdt2.setValue(gs.endOfThisMonth());
    }

    Scoped equivalent

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

    GlideSystem - endOfThisQuarter()

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

    Table 59. Parameters
    Name Type Description
    None
    Table 60. Returns
    Type Description
    String GMT date and time for the end of this quarter.

    Format: yyyy-mm-dd hh:mm:ss

    This example shows how to use endOfThisQuarter() to set the GlideDateTime object to the end of the current month.

    setEndDate : function(dt) {
      var gdt2 = new GlideDateTime(dt);
      gdt2.setValue(gs.endOfThisQuarter());
    }

    Scoped equivalent

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

    GlideSystem - endOfThisWeek()

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

    Table 61. Parameters
    Name Type Description
    None
    Table 62. Returns
    Type Description
    String GMT date and time for the end of this week.

    Format: yyyy-mm-dd hh:mm:ss

    This example shows how to use endOfThisWeek() to set the GlideDateTime object to the end of the current month.

    setEndDate : function(dt) {
      var gdt2 = new GlideDateTime(dt);
      gdt2.setValue(gs.endOfThisWeek());
    }

    Scoped equivalent

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

    GlideSystem - endOfThisYear()

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

    Table 63. Parameters
    Name Type Description
    None
    Table 64. Returns
    Type Description
    String GMT date and time for the end of this year.

    Format yyyy-mm-dd hh:mm:ss

    This example shows how to use endOfThisYear() to set the GlideDateTime object to the end of the current month.

    setEndDate : function(dt) {
      var gdt2 = new GlideDateTime(dt);
      gdt2.setValue(gs.endOfThisYear());
    }

    Scoped equivalent

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

    GlideSystem - endOfToday()

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

    Table 65. Parameters
    Name Type Description
    None
    Table 66. Returns
    Type Description
    String GMT in the format yyyy-mm-dd hh:mm:ss.
    var beginToday = gs.beginningOfToday(); 
            var endToday = gs.endOfToday(); 
            var beginTomorrow = gs.beginningOfTomorrow(); 
            var endTomorrow = gs.endOfTomorrow(); 
            var beginYesterday = gs.beginningOfYesterday(); 
            var endYesterday = gs.endOfYesterday(); 
            
            gs.info('beginningOfToday: ' + beginToday); 
            gs.info('endOfToday: ' + endToday); 
            gs.info('-----------'); 
            gs.info('beginningOfTomorrow: ' + beginTomorrow); 
            gs.info('endOfTomorrow: ' + endTomorrow); 
            gs.info('beginningOfYesterday: ' + beginYesterday); 
            gs.info('endOfYesterday: ' + endYesterday); 
            gs.info('-----------'); 
            var gdt1 = new GlideDateTime(beginToday); 
            var gdt2 = new GlideDateTime(beginTomorrow); 
            var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2 
            gs.info('BeginTomorrow: ' + dur.getDisplayValue()); 
            
            var gdt1 = new GlideDateTime(endToday); 
            var gdt2 = new GlideDateTime(endTomorrow); 
            var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2 
            gs.info('EndTomorrow: ' + dur.getDisplayValue()); 
            
            var gdt1 = new GlideDateTime(beginToday); 
            var gdt2 = new GlideDateTime(beginYesterday); 
            var dur = GlideDateTime.subtract(gdt2, gdt1); //the difference between gdt1 and gdt2 
            gs.info('BeginningYesterday: ' + dur.getDisplayValue()); 
            
            var gdt1 = new GlideDateTime(endToday); 
            var gdt2 = new GlideDateTime(endYesterday); 
            var dur = GlideDateTime.subtract(gdt2, gdt1); //the difference between gdt1 and gdt2 
            gs.info('EndYesterday: ' + dur.getDisplayValue());

    GlideSystem - endOfTomorrow()

    Retrieves the date and time for the end of tomorrow in GMT.

    Table 67. Parameters
    Name Type Description
    None
    Table 68. Returns
    Type Description
    String GMT in the format yyyy-mm-dd hh:mm:ss.
    var tomorrowEnd = new GlideDateTime();
    tomorrowEnd.setValue(gs.endOfTomorrow());

    GlideSystem - endOfYesterday()

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

    Table 69. Parameters
    Name Type Description
    None
    Table 70. Returns
    Type Description
    String GMT in the format (yyyy-mm-dd huh:mm:ss).
    var yesterdayEnd = new GlideDateTime();
    yesterdayEnd.setValue(gs.endOfYesterday());

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

    Queues an event for the event manager.

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

    Scoped equivalent

    To use the eventQueue() method in a scoped application, use the corresponding scoped method: eventQueue().

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

    Queues an event for the event manager at a specified date and time.

    Table 73. Parameters
    Name Type Description
    name String Name of the event being queued.
    glideRecord Object 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 Date and time to process this event.
    Table 74. Returns
    Type Description
    void
    if (current.operation() != 'insert' && current.comments.changes()) {
        gs.eventQueueScheduled("incident.commented", current, gs.getUserID(), gs.getUserName(), new GlideDateTime('2018-06-02 20:00:00'));
    }

    Scoped equivalent

    To use the eventQueueScheduled() method in a scoped application, use the corresponding scoped method: eventQueueScheduled().

    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 75. Parameters
    Name Type Description
    None
    Table 76. Returns
    Type Description
    void

    This example shows how to parse through and pass back error messages and then clears the messages using flushMessages().

    MySessionUtil.getSessionError = function() {
      var msg = null;
      var msgs = gs.getErrorMessages().toArray();
      if (msgs.length > 0) {
        msg = msgs[0] + '';
        gs.flushMessages();
      }
      return msg;
    };
    

    GlideSystem - getAvatar()

    Returns the file path to the user's avatar.

    Table 77. Parameters
    Name Type Description
    None
    Table 78. 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()

    Returns the name of the current application scope.

    Table 79. Parameters
    Name Type Description
    None
    Table 80. Returns
    Type Description
    String Current scope name.

    This example shows how to use getCurrentScopeName() to get the scope of the processor.

    var incident_GR = new GlideRecord('Incident');
    
    if (incident_GR.get("2e3f6baddb9ad600added8fdbf9618cb")) {
      gs.debug("processor scope = "+ gs.getCurrentScopeName());
      var w = new global.Workflow();
      var context = w.startFlow('1f4a4baddb9ad600affed8fdbf9619bc', incident_GR, "update");   //id = id workflow
    }

    Scoped equivalent

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

    GlideSystem - getDateFormat()

    Returns the date format associated with the current user.

    Table 81. Parameters
    Name Type Description
    None
    Table 82. Returns
    Type Description
    String The date format associated with the current user.

    The following example returns the date format associated with the user.

    var userDateFormat = gs. getDateFormat();
    gs.info(userDateFormat);
    

    Output:

    yyyy-MM-dd

    GlideSystem - getDateTimeFormat()

    Returns the date and time format associated with the current user.

    Table 83. Parameters
    Name Type Description
    None
    Table 84. Returns
    Type Description
    String The date and time format associated with the current user.

    The following example returns the format of the date and time that is associated with the user.

    var userDateTimeFormat = gs.getDateTimeFormat();
    gs.info(userDateTimeFormat);
    

    Output:

    yyyy-MM-dd HH:mm:ss

    GlideSystem - getDisplayColumn(String tableName)

    Retrieves the display column for the table.

    Table 85. Parameters
    Name Type Description
    tableName String Name of the table from which to get the display column name.
    Table 86. 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 specified record.

    Table 87. Parameters
    Name Type Description
    tableName String Name of the table.
    recordID String Sys_id for the record.
    fieldName String Name of the field whose display value to return.
    Table 88. Returns
    Type Description
    String Display value for the field.

    This example shows how to use getDisplayValueFor() to return the display value of the number field.

    var value = gs.getDisplayValueFor(current.getTableName(),current.getValue('sys_id'),'number');
    

    GlideSystem - getErrorMessages()

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

    Table 89. Parameters
    Name Type Description
    None
    Table 90. Returns
    Type Description
    String List of error messages

    This example shows how to parse through and pass back error messages using getErrorMessages().

    MySessionUtil.getSessionError = function() {
      var msg = null;
      var msgs = gs.getErrorMessages().toArray();
      if (msgs.length > 0) {
        msg = msgs[0] + '';
        gs.flushMessages();
      }
      return msg;
    };
    

    Scoped equivalent

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

    GlideSystem - getEscapedProperty(String key, Object substituteObject)

    Retrieves the property and escapes it for XML parsing.

    Table 91. Parameters
    Name Type Description
    key String Key for the property whose value should be returned.
    substituteObject Object Optional. Object to return if the property is not found.
    Table 92. Returns
    Type Description
    String Property, or the substituteObject if the property is not found.
    var propValue = gs.getEscapedProperty("com.example.my_test_property");
    gs.addInfoMessage("This is my property value " + propValue);

    GlideSystem - getImpersonatingUserDisplayName()

    Returns the display name of the impersonating user.

    Table 93. Parameters
    Name Type Description
    None
    Table 94. Returns
    Type Description
    String Display name of the impersonating user.

    This example shows how to obtain the impersonator's user display name.

    var user = gs.getUserDisplayName();
    gs.print ("The current user display name is: " + user);
    
    var name = gs.getImpersonatingUserDisplayName(); 
    gs.print("Impersonating user display name: " + name);
    Output:
    The current user display name is: abel.tuter
    Impersonating user display name: admin

    GlideSystem - getImpersonatingUserName()

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

    Table 95. Parameters
    Name Type Description
    None
    Table 96. Returns
    Type Description
    String Name of impersonating user

    This example shows how to obtain the impersonator's user name.

    var name = gs.getImpersonatingUserName();
    var actual_user = null;
    if (name == null || name == '')
      actual_user = user;
    else
      actual_user = Packages.com.glide.sys.User.getUser(name);
    
    var recent_impersonations = actual_user.getPreference('recent.impersonations');
    var admin_role=actual_user.hasRole("admin");

    GlideSystem - getInfoMessages()

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

    Table 97. Parameters
    Name Type Description
    None
    Table 98. Returns
    Type Description
    String List of info messages.

    This example shows how to obtain the information messages.

    var messages = gs.getInfoMessages();
    if (messages.toString().indexOf('Conflicts Detected') == -1)
      gs.addInfoMessage(msg);

    GlideSystem - getInitials()

    Returns the user's initials.

    Table 99. Parameters
    Name Type Description
    None
    Table 100. 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 from the Message [sys_ui_message] table to display in a UI.

    If the specified message identifier (key) exists in the Message [sys_ui_message] table for the current language, the method returns the translated message. If the specified message identifier does not exist for the current language, the method returns the English version of the message. If the message identifier does not exist in the table, then it returns the message ID.

    For additional information about the Message table, see Message table.

    Note:
    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 101. Parameters
    Name Type Description
    messageID String Message identifier. You can locate this value in the Key field of the Message [sys_ui_message] table. Note the Key field may look exactly like the actual message string.
    args Object Optional. List of strings or other values defined by java.text.MessageFormat that replace the variables within the specified message.

    For example: gs.getMessage("Abort adding action '{0}', same subflow can't be added twice in this subflow.", current.action.name);

    In this example '{0}' is replaced with the content of current.action.name.

    Note:
    The passed in values are not translated. They are inserted verbatim in the message.
    Table 102. Returns
    Type Description
    String Requested UI message.

    This example shows the message returned for the current user when Spanish is the current language.

    var my_message = gs.getMessage("rows will not be updated");
    alert(my_message);

    Output:

    las filas no se actualizarán

    This example shows how to replace a single variable within a message.

    // current.action.name is "update record"
    var my_message = gs.getMessage("Abort adding action '{0}', same subflow can't be added twice in this subflow.", current.action.name);
    alert(my_message);

    Output:

    Abort adding action update record, same subflow can't be added twice in this subflow.

    This example shows how to replace multiple variables within a message.

    // current.sub_flow.name is 'schedule users'
    // current.action.name is "update record"
    var my_message = gs.getMessage("Abort adding action '{0}', same subflow can't be added twice in {1} subflow.", [current.action.name, current.sub_flow.name]);
    alert(my_message);

    Output:

    Abort adding action update record, same subflow can't be added twice in schedule users subflow.

    Scoped equivalent

    To use the getMessage() method in a scoped application, use the corresponding scoped method: getMessage().

    GlideSystem - getMessageS(String messageID, Object args)

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

    If the specified message identifier (key) exists in the Message [sys_ui_message] table for the current language, the method returns the translated message. If the specified message identifier does not exist for the current language, the method returns the English version of the message. If the message identifier does not exist in the table, then it returns the message ID.

    For additional information about the Message table, see Message table.

    Useful if you are inserting into a JavaScript expression from Jelly.

    Table 103. Parameters
    Name Type Description
    MessageID String Message identifier. You can locate this value in the Key field of the Message [sys_ui_message] table. Note the Key field may look exactly like the actual message string.
    args Object Optional. List of strings or other values defined by java.text.MessageFormat that replace the variables within the specified message.

    For example: gs.getMessage("Abort adding action '{0}', same subflow can't be added twice in this subflow.", current.action.name);

    In this example '{0}' is replaced with the content of current.action.name.

    Note:
    The passed in values are not translated. They are inserted verbatim in the message.
    Table 104. Returns
    Type Description
    String Specified 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 - getMessageLang(String message, String language, Array args)

    Translates the specified message into the specified language.

    You can also embed variables in the passed message. The method resolves those variables with the values passed in the args array.

    Table 105. Parameters
    Name Type Description
    message String Message to translate.
    language String Language in which to translate the message.

    Format: BCP 47 standard

    args Array Optional. List of strings or other values defined by java.text.MessageFormat that replace the variables within the specified message.

    For example: gs.getMessageLang("Abort adding action '{0}', same subflow can't be added twice in this subflow.", current.action.name);

    In this example '{0}' is replaced with the content of current.action.name.

    Note:
    The passed in values are not translated. They are inserted verbatim in the message.
    Table 106. Returns
    Type Description
    String Translated message.

    The following example transforms the specified message into Spanish.

    var my_message = gs.getMessageLang("New email", "es");
    gs.info(my_message);

    Output:

    Nuevo correo electrónico

    The following example shows how to replace variables within a message.

    var my_message = gs.getMessageLang("There are {0} new emails for {1}", "es", [current.numEmails, current.userName]);
    gs.info(my_message);

    Output:

    Hay 7 correos nuevos para John Smith

    GlideSystem - getNodeName(Object obj, Number index)

    Returns the node name for the specified index.

    Table 107. Parameters
    Name Type Description
    obj Object Object to examine.
    index Number Index from which to obtain the node name.
    Table 108. Returns
    Type Description
    String Node's name
    function doInsert(nodeList) {
      gs.print('Doing insert');
      var task = new GlideRecord('task');
      task.initialize();
      for (var x=0; x < nodeList.size(); x++) {
        var name = gs.getNodeName(nodeList, x);
        var value = gs.getNodeValue(nodeList, x);
        task.setValue(name, value);
      }
      task.insert();
    }

    GlideSystem - getNodeValue(Object obj, Number index)

    Returns the node value for the specified index.

    Table 109. Parameters
    Name Type Description
    obj Object Object to examine.
    index Number Index from which to get the node valu.e
    Table 110. Returns
    Type Description
    Object Node value
    function doInsert(nodeList) {
      gs.print('Doing insert');
      var task = new GlideRecord('task');
      task.initialize();
      for (var x=0; x < nodeList.size(); x++) {
        var name = gs.getNodeName(nodeList, x);
        var value = gs.getNodeValue(nodeList, x);
        task.setValue(name, value);
      }
      task.insert();
    }

    GlideSystem - getPreference(String key, Object default)

    Returns the specified user preference.

    Table 111. Parameters
    Name Type Description
    key String Key for the preference.
    default Object Default value to use if the specified preference is not found.
    Table 112. Returns
    Type Description
    String Preference value. If no preference, returns the specified default value.
    function getSelectedProject() {
      var array= new Array();
      var prj_id = gs.getPreference("prj_id"); //This will fetch value from user preference
      var gr = new GlideRecord('pm_project_task');
      gr.addQuery('parent', prj_id);
      gr.addActiveQuery();
      while(gr.next()) {
        array.push(gr.sys_id.toString());
      }
      return array;
    }

    GlideSystem - getProperty(String key, Object alt)

    Returns the value of a Glide property. If the property is not found, returns the specified alt value.

    Table 113. Parameters
    Name Type Description
    key String Key for the property whose value should be returned.
    alt Object Optional. Alternate object to return if the property is not found.
    Table 114. Returns
    Type Description
    String Value of the Glide property, or the alternate object defined above.
    //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.

    Note:
    The script is not executed by this function, it is only checked for syntax errors.
    Table 115. Parameters
    Name Type Description
    script String Script to check for errors.
    Table 116. Returns
    Type Description
    String Error message. Null if there is no error.
    if (gs.isValidScript(current.script) == false)
      {
        current.setAbortAction(true);
        var error = gs.getScriptError(current.script);
        current.script.setError(error);
      }

    GlideSystem - getSession()

    Returns a GlideSession object.

    Table 117. Parameters
    Name Type Description
    None
    Table 118. Returns
    Type Description
    GlideSession Object GlideSession object for the current session
    if(!gs.hasRole("admin") && gs.getSession().isInteractive() && gs.getUserName() != "guest"){
      var qc = current.addQuery('u_visibility', "both");
      qc.addOrCondition('u_visibility', '');
      if (gs.getImpersonatingUserName() != null) {
        gs.getSession().clearClientData('navQuery');
      }
      var navQuery = gs.getSession().getClientData('navQuery');
      if (navQuery == null) {
        var isManager = gs.getUser().getRecord().getValue('u_is_manager');
          if (!isManager) {
            qc.addOrCondition('u_visibility', 'nonmanager');
            gs.getSession().putClientData('navQuery', 'nonmanager');
          } else {
            qc.addOrCondition('u_visibility', 'manager');
            gs.getSession().putClientData('navQuery', 'manager');
            }
      } else {
      qc.addOrCondition('u_visibility', navQuery);
      }   
    }

    Scoped equivalent

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

    GlideSystem - getSessionID()

    Returns the GlideSession session ID.

    Table 119. Parameters
    Name Type Description
    None
    Table 120. Returns
    Type Description
    String Session ID
    var gr_NOW = new GlideRecord('v_user_session');
    var sessionId = gs.getSessionID();
    gs.log("Session ID is: " + sessionId);

    Output

    Session ID is: FEE589B3DB7EE4103DD9C39D139619D7

    Scoped equivalent

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

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

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

    Table 121. Parameters
    Name Type Description
    tableName String Table name
    fieldName String Field name
    fieldValue String Field value
    Table 122. Returns
    Type Description
    String Style of the specified field.
    var returnString = gs.getStyle('<tableName>', '<fieldName>', '<fieldValue>');
    gs.print(returnString);

    GlideSystem - getTimeFormat()

    Returns the time format associated with the current user.

    Table 123. Parameters
    Name Type Description
    None
    Table 124. Returns
    Type Description
    String The time format associated with the current user.
    var userTimeFormat = gs. getTimeFormat();
    gs.info(userTimeFormat);
    

    Output:

    HH:mm:ss

    GlideSystem - getUser()

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

    Table 125. Parameters
    Name Type Description
    None
    Table 126. Returns
    Type Description
    GlideUser Reference to a user object for the current user.

    The following example shows how to get the current user object.

    var user = gs.getUser();
    gs.print ("The current user is: " + user);
    Output:
    The current user is: com.glide.sys.User@db5dd9

    The following example shows how to check whether the current user has the workflow_admin role.

    var role = gs.getUser().hasRole('workflow_admin');
    gs.print ("Does the current user have the workflow_admin role: " + role);
    Output:
    Does the current user have the workflow_admin role: true

    Scoped equivalent

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

    GlideSystem - getUserDisplayName()

    Gets the display name of the current user.

    Table 127. Parameters
    Name Type Description
    None
    Table 128. Returns
    Type Description
    String The name field of the current user.

    For example, this method returns Abel Tuter as opposed to abel.tuter.

    This example gets the current user's display name.

    gs.info(gs.getUserDisplayName());

    Output:

    System Administrator

    Scoped equivalent

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

    GlideSystem - getUserID()

    Returns the sys_id of the current user.

    Table 129. Parameters
    Name Type Description
    None
    Table 130. Returns
    Type Description
    String Sys_id of the current user.

    This example gets the current user's sys_id.

    var currentUserId = gs.getUserID();
    gs.print("Current user ID: " + currentUserId);
    Output:
    Current user ID: 6816f79cc0a8016401c5a33be04be441

    Scoped equivalent

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

    GlideSystem - getUserName()

    Returns the user name of the current user.

    Table 131. Parameters
    Name Type Description
    None
    Table 132. Returns
    Type Description
    String The user name of the current user.

    For example, this method returns abel.tuter as opposed to Abel Tuter.

    This example gets the user name of the current user and an impersonated user.

    var user = gs.getUserName();
    gs.info("The current user name is: " + user);
    
    var impUser = new GlideImpersonate();
    impUser.impersonate("62826bf03710200044e0bfc8bcbe5df1");
    var user2 = gs.getUserName();
    gs.info("The impersonated user name is: " + user2);
    Output:
    The current user name is: admin
    The impersonated user name is: abel.tuter

    Scoped equivalent

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

    GlideSystem - getUserNameByUserID(String user_id)

    Returns the user display name based on a provided user login name.

    Table 133. Parameters
    Name Type Description
    user_id String Login name of the user from which to retrieve the associated display name.
    Table 134. Returns
    Type Description
    String Display name of the requested user.
    Note:
    If this method can't find a user with the requested ID, it returns the input value provided.

    The following example shows how to get the specified user's display name.

    var displayName = gs.getUserNameByUserID('abel.tuter');
    gs.info('User display name is: ' + displayName);
    Output:
    User display name is: Abel Tuter

    GlideSystem - getXMLNodeList(String xml)

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

    Table 135. Parameters
    Name Type Description
    xml String XML document to parse.
    Table 136. Returns
    Type Description
    Array list List of names and values of the outer most XML node.

    The following example shows how to get a list of XML nodes and their associated values in an array list.

    var nodeList = gs.getXMLNodeList("<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>");
    gs.print ("The node contains: " + nodeList);
    
    Output:
    The node contains: [to : Tove, from : Jani, heading : Reminder, body : Don't forget me this weekend!]
    

    GlideSystem - getXMLText(String xml, String xpathQuery)

    Returns the XML text for the first element in the XML string that matches the XPath query.

    Table 137. Parameters
    Name Type Description
    xml String XML string to search.
    xpathQuery String XPath query to match.
    Table 138. Returns
    Type Description
    String XML node matching the search parameters.

    The following example shows how to get the value of a specified XML element within a passed-in node.

    var nodeList = gs.getXMLText("<outer><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note></outer>", "//from");
    gs.print ("The from element contains: " + nodeList);
    Output:
    The from element contains: Jani

    GlideSystem - hasRole(String roleName)

    Determines if the current user has at least one of the passed-in roles.

    Table 139. Parameters
    Name Type Description
    roleName String Comma-separated list of roles.
    Table 140. Returns
    Type Description
    Boolean Flag that indicates whether the current user has at least one of the specified roles.
    Possible values:
    • true: User has at least one of the passed-in roles. Also returns true if the user has the administrator role.
    • false: User does not have any of the passed-in roles.

    The following example shows how to check whether the current user has the admin or groups_admin role.

    if (!gs.hasRole("admin, 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
    }

    Scoped equivalent

    To use the hasRole() method in a scoped application, use the corresponding scoped method: hasRole().

    GlideSystem - hasRoleInGroup(Object roleName, Object group)

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

    Table 141. Parameters
    Name Type Description
    roleName Object Name of the role.
    group Object Sys_id of the group to check for the specified role.
    Table 142. Returns
    Type Description
    Boolean Flag that indicates whether the current user has the specified role in the specified group.
    Possible values:
    • true: The logged-in user is assigned to the specified role in the specified group.
    • false: The logged-in user is not assigned to the specified role in the specified group.

    The following example shows how to check whether the sys_user_group group has the role_name role.

    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 the specified number of hours ago. The returned value is adjusted for the time zone of the instance.

    Table 143. Parameters
    Name Type Description
    hours Number Number of hours ago.
    Table 144. Returns
    Type Description
    String UTC date and time for the specified number of hours ago.

    Format: yyyy-mm-dd hh:mm:ss

    var currentDateTime = gs.hoursAgo(0);
    gs.info("Current date/time: " + currentDateTime);
    
    var agoDateTime = gs.hoursAgo(1);
    gs.info("Ago date/time: " + agoDateTime);
    Output
    Current date/time: 2021-03-17 20:53:25
    Ago date/time: 2021-03-17 19:53:25

    Scoped equivalent

    To use the hoursAgo() method in a scoped application, use the corresponding scoped method: hoursAgo().

    GlideSystem - hoursAgoEnd(Number hours)

    Returns a date and time for the end of the hour for the specified number of hours ago. The returned value is adjusted for the time zone of the instance.

    Table 145. Parameters
    Name Type Description
    hours Number (Integer) Number of hours ago.
    Table 146. Returns
    Type Description
    String UTC date and time for the end of the specified number of hours ago.

    Format: yyyy-mm-dd hh:mm:ss

    var currentDateTime = gs.hoursAgoEnd(0);
    gs.print("Current date/time: " + currentDateTime);
    
    var agoDateTime = gs.hoursAgoEnd(1);
    gs.print("Ago date/time: " + agoDateTime);
    Output
    Current date/time: 2021-03-17 20:59:59
    Ago date/time: 2021-03-17 19:59:59

    Scoped equivalent

    To use the hoursAgoEnd() method in a scoped application, use the corresponding scoped method: hoursAgoEnd().

    GlideSystem - hoursAgoStart(Number hours)

    Returns a date and time for the start of the hour for the specified number of hours ago. The returned value is adjusted for the time zone of the instance.

    Table 147. Parameters
    Name Type Description
    hours Number Number of hours ago.
    Table 148. Returns
    Type Description
    String UTC date and time for the end of the specified number of hours ago.

    Format: yyyy-mm-dd hh:mm:ss

    var currentDateTime = gs.hoursAgoStart(0);
    gs.print("Current date/time: " + currentDateTime);
    
    var agoDateTime = gs.hoursAgoStart(1);
    gs.print("Ago date/time: " + agoDateTime);
    Output
    Current date/time: 2021-03-17 20:00:00
    Ago date/time: 2021-03-17 19:00:00

    Scoped equivalent

    To use the hoursAgoStart() method in a scoped application, use the corresponding scoped method: hoursAgoStart().

    GlideSystem - isFirstDayOfMonth(Object date)

    Checks whether the date in the specified date object is the first day of the month.

    Table 149. Parameters
    Name Type Description
    date Object Date object on which to check the date, such as GlideDateTime or GlideDate.
    Table 150. Returns
    Type Description
    Boolean Flag that indicates whether the date in the specified date object is the first day of the month.
    Possible values:
    • true: First day of the month.
    • false: Not the first day of the month.

    This example show how to determine whether the date in the specified date object is the first day of the month.

    var gdt = new GlideDateTime();
    gdt.setValue('2021-04-01 12:00:00');
    var currentDay = gs.isFirstDayOfMonth(gdt);
    gs.print("First day of month: " + currentDay);
    
    gdt.setValue('2021-04-21 12:00:00');
    var currentDay = gs.isFirstDayOfMonth(gdt);
    gs.print("First day of month: " + currentDay);
    Output
    First day of month: true
    First day of month: false

    GlideSystem - isFirstDayOfWeek(Object date)

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

    Table 151. Parameters
    Name Type Description
    date Object Date object on which to check the date, such as GlideDateTime or GlideDate.
    Table 152. Returns
    Type Description
    Boolean Flag that indicates whether the date in the current date object is the first day of the week (Monday).
    Possible values:
    • true: First day of the week.
    • false: Not the first day of the week.

    This example show how to determine whether the date in the specified date object is the first day of the week.

    var gdt = new GlideDateTime();
    gdt.setValue('2021-03-02 12:00:00');
    var currentDay = gs.isFirstDayOfWeek(gdt);
    gs.info("First day of week: " + currentDay);
    
    gdt.setValue('2021-03-22 12:00:00');
    var currentDay = gs.isFirstDayOfWeek(gdt);
    gs.info("First day of week: " + currentDay);
    Output
    First day of week: false
    First day of week: true

    GlideSystem - isFirstDayOfYear(Object date)

    Checks whether the date in the specified date object is the first day of the year.

    Table 153. Parameters
    Name Type Description
    date Object Date object on which to check the date, such as GlideDateTime or GlideDate.
    Table 154. Returns
    Type Description
    Boolean Flag that indicates whether the date in the specified date object is the first day of the year.
    Possible values:
    • true: First day of the year.
    • false: Not the first day of the year.

    This example show how to determine whether the date in the specified date object is the first day of the year.

    var gdt = new GlideDateTime();
    gdt.setValue('2020-12-31 12:00:00');
    var currentDay = gs.isFirstDayOfYear(gdt);
    gs.info("First day of year: " + currentDay);
    
    gdt.setValue('2021-01-01 12:00:00');
    var currentDay = gs.isFirstDayOfYear(gdt);
    gs.info("First day of year: " + currentDay);
    Output
    First day of year: false
    First day of year: true

    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 155. Parameters
    Name Type Description
    None
    Table 156. Returns
    Type Description
    Boolean Flag that indicates whether the session is interactive.
    Possible values:
    • true: Session is interactive.
    • false: Session is not interactive.
    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);
      }
    }

    Scoped equivalent

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

    GlideSystem - isLastDayofMonth(Object date)

    Checks whether the date in the specified date object is the last day of the month.

    Table 157. Parameters
    Name Type Description
    date Object Date object on which to check the date, such as GlideDateTime or GlideDate.
    Table 158. Returns
    Type Description
    Boolean Flag that indicates whether the date in the specified date object is the last day of the month.
    Possible values:
    • true: Last day of the month.
    • false: Not the last day of the month.

    This example show how to determine whether the date in the specified date object is the last day of the month.

    var gdt = new GlideDate();
    gdt.setValue('2020-12-31 12:00:00');
    var currentDay = gs.isLastDayOfMonth(gdt);
    gs.print("First day of year: " + currentDay);
    
    gdt.setValue('2021-01-01 12:00:00');
    var currentDay = gs.isLastDayOfMonth(gdt);
    gs.print("First day of year: " + currentDay);
    Output
    Last day of month: true
    Last day of month: false

    GlideSystem - isLastDayOfWeek(Object date)

    Checks whether the date in the specified date object is the last day of the week. This method uses the ISO standard of Sunday being the last day of the week.

    Table 159. Parameters
    Name Type Description
    date Object Date object on which to check the date, such as GlideDateTime or GlideDate.
    Table 160. Returns
    Type Description
    Boolean Flag that indicates whether the date in the current date object is the last day of the week (Sunday).
    Possible values:
    • true: Last day of the week.
    • false: Not the last day of the week.

    This example show how to determine whether the date in the specified date object is the last day of the week.

    var gdt = new GlideDate();
    gdt.setValue('2021-03-01 12:00:00');
    var currentDay = gs.isLastDayOfWeek(gdt);
    gs.info("Last day of week: " + currentDay);
    
    gdt.setValue('2021-03-21 12:00:00');
    var currentDay = gs.isLastDayOfWeek(gdt);
    gs.info("Last day of week: " + currentDay);
    Output
    First day of week: false
    First day of week: true

    GlideSystem - isLastDayOfYear(Object date)

    Checks whether the date in the specified date object is the last day of the year.

    Table 161. Parameters
    Name Type Description
    date Object Date object on which to check the date, such as GlideDateTime or GlideDate.
    Table 162. Returns
    Type Description
    Boolean Flag that indicates whether the date in the current date object is the last day of the year.
    Possible values:
    • true: Last day of the year.
    • false: Not the last day of the year.

    This example show how to determine whether the date in the specified date object is the last day of the year.

    var gdt = new GlideDateTime();
    gdt.setValue('2020-12-31 12:00:00');
    var currentDay = gs.isLastDayOfYear(gdt);
    gs.info("Last day of year: " + currentDay);
    
    gdt.setValue('2021-01-01 12:00:00');
    var currentDay = gs.isLastDayOfYear(gdt);
    gs.info("Last day of year: " + currentDay);
    Output
    Last day of year: true
    Last day of year: false

    GlideSystem - isLoggedIn()

    Determines if the current user is currently logged in.

    Table 163. Parameters
    Name Type Description
    None
    Table 164. Returns
    Type Description
    Boolean Flag that indicates whether the current user is logged in.
    Possible values:
    • true: User is logged in.
    • false: User is not logged in.

    This example show how to determine whether the current user is logged in.

    if(gs.isLoggedIn())
      gs.info("Current user is logged in");
    else
      gs.info("Current user is NOT logged in");
    Output
    Current user is logged in

    Scoped equivalent

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

    GlideSystem - isMobile()

    Determines whether the request came from a mobile device.

    You can use this method in UI action conditions and business rules.

    Table 165. Parameters
    Name Type Description
    None
    Table 166. Returns
    Type Description
    Boolean Flag that indicates whether the request came from a mobile device.
    Possible values:
    • true: Mobile device.
    • false: Non-mobile device.

    This example show how to determine whether the current device is a mobile device.

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

    Scoped equivalent

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

    GlideSystem - lastWeek()

    Returns the date and time one week ago in GMT.

    Table 167. Parameters
    Name Type Description
    None
    Table 168. Returns
    Type Description
    String Date and time one week ago.

    Format: yyyy-MM-dd hh:mm:ss

    This example show how to obtain the date that is one week from the date in the current date object.

    var gdt = new GlideDateTime();
    gdt.setValue('2021-03-22 01:00:00');
    
    gs.info("Current date: " + gs.nowDateTime());
    
    gs.info("One week earlier: " + gs.lastWeek());
    Output
    Current date: 2021-03-22 15:27:07
    One week earlier: 2021-03-15 15:27:07

    GlideSystem - log(String message, String source)

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

    Table 169. Parameters
    Name Type Description
    message String Message to log.
    source String Optional. Source of the message.
    Table 170. Returns
    Type Description
    void

    The following example shows how to post a log entry using constants and variables.

    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 171. Parameters
    Name Type Description
    message String Error message to log.
    source String Optional. Source of the message.
    Table 172. Returns
    Type Description
    void

    The following example logs an error if the Incident table cannot be found.

    var gr_NOW = new GlideRecord("incident");
    if (!gr_NOW.isValid()) {
      gs.logError('Incident table could not be found');
      return;
    }

    GlideSystem - logWarning(String message, String source)

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

    Table 173. Parameters
    Name Type Description
    message String Message to log.
    source String Optional. Source of the message.
    Table 174. Returns
    Type Description
    void

    The following example logs a warning if the Incident table cannot be found.

    var gr_NOW = new GlideRecord("incident");
    if (!gr_NOW.isValid()) {
      gs.logWarning('Incident table could not be found');
      return;
    }

    GlideSystem - minutesAgo(Number minutes)

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

    Table 175. Parameters
    Name Type Description
    minutes Number Number of minutes in the past to return.
    Table 176. Returns
    Type Description
    String UTC date and time for the specified number of minutes ago.

    Format: yyyy-mm-dd hh:mm:ss

    This example shows how to use the minutesAgo() method in an addQuery() call.

    // 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 now_GR = new GlideRecord('sysevent');
    now_GR.addQuery('name', 'login.failed');
    now_GR.addQuery('parm1', event.parm1.toString());
    now_GR.addQuery('sys_created_on','>=', gs.minutesAgo(15));
    now_GR.query();
    var rowCount = now_GR.getRowCount();
    if(rowCount >= 5){
      var now_GR = new GlideRecord("sys_user");
      now_GR.addQuery("user_name", event.parm1.toString());
      now_GR.query();
      if (now_GR.next()) {
        now_GR.locked_out = true;
        now_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 177. Parameters
    Name Type Description
    minutes Number Integer number of minutes ago, such as 5 or 11.
    Table 178. Returns
    Type Description
    String GMT the specified number of minutes ago, at the end of the minute (59 seconds).

    Format: yyyy-mm-dd hh:mm:ss

    The following example displays the current date and time and the date and time 30 minutes ago at the end of the minute in GMT.

    var nowDateTime = new GlideDateTime();
    gs.print("Now: " + nowDateTime);
    var thirtyMinutesAgoDateTime = gs.minutesAgoEnd(30);
    gs.print("Thirty minutes ago end time: " + thirtyMinutesAgoDateTime);

    Output

    Now: 2021-10-20 15:22:13
    Thirty minutes ago end time: 2021-10-20 14:52:59

    Scoped equivalent

    To use the minutesAgoEnd() method in a scoped application, use the corresponding scoped method: minutesAgoEnd().

    GlideSystem - minutesAgoStart(Number minutes)

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

    Table 179. Parameters
    Name Type Description
    minutes Number Integer number of minutes ago, such as 15 or 112.
    Table 180. Returns
    Type Description
    String GMT the specified number of minutes ago, at the start of the minute.

    Format: yyyy-mm-dd hh:mm:ss

    The following example displays the current date and time and the date and time 30 minutes ago at the start of the minute in GMT.

    var nowDateTime = new GlideDateTime();
    gs.info("Now: " + nowDateTime);
    var thirtyMinutesAgoDateTime = gs.minutesAgoStart(30);
    gs.info("Thirty minutes ago: " + thirtyMinutesAgoDateTime);

    Output

    Now: 2021-10-20 14:56:18
    Thirty minutes ago: 2021-10-20 14:26:00

    Scoped equivalent

    To use the minutesAgoStart() method in a scoped application, use the corresponding scoped method: minutesAgoStart().

    GlideSystem - monthsAgo(Number months)

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

    Table 181. Parameters
    Name Type Description
    months Number Integer number of months ago.
    Table 182. Returns
    Type Description
    String GMT of the specified number of months ago at the exact same time.

    Format: yyyy-mm-dd hh:mm:ss

    The following example displays the current date and time and the date and time one month ago at the same time in GMT.

    var nowDateTime = new GlideDateTime();
    gs.info("Now: " + nowDateTime);
    var oneMonthAgoDateTime = gs.monthsAgo(1);
    gs.info("One month ago: " + oneMonthAgoDateTime);

    Output

    Now: 2021-10-20 15:29:15
    One month ago: 2021-09-20 15:29:15

    Scoped equivalent

    To use the monthsAgo() method in a scoped application, use the corresponding scoped method: monthsAgo().

    GlideSystem - monthsAgoEnd(Number months)

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

    Table 183. Parameters
    Name Type Description
    months Number Integer number of months, such as 4 or 16.
    Table 184. Returns
    Type Description
    String GMT end of the month the specified number of months ago.

    Format: yyyy-mm-dd hh:mm:ss

    The following example displays the current date and time and the date and time two months ago at the end of the business month.

    var nowDateTime = new GlideDateTime();
    gs.info("Now: " + nowDateTime);
    var endOfTheMonthDateTime = gs.monthsAgoEnd(2);
    gs.info("End of the month: " + endOfTheMonthDateTime);

    Output

    Now: 2021-10-20 19:23:35
    End of the month: 2021-09-01 06:59:59

    GlideSystem - monthsAgoStart(Number months)

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

    Table 185. Parameters
    Name Type Description
    months Number Integer number of months ago, such as 5 or 14.
    Table 186. Returns
    Type Description
    String GMT start of the month the specified number of months ago.

    Format: yyyy-mm-dd hh:mm:ss

    The following example displays the current date and time and the date and time three months ago in GMT.

    var nowDateTime = new GlideDateTime();
    gs.info("Now: " + nowDateTime);
    var threeMonthsAgoDateTime = gs.monthsAgoStart(3);
    gs.info("Three months ago start date and time: " + threeMonthsAgoDateTime);

    Output

    Now: 2021-10-20 15:05:27
    Three months ago start date and time: 2021-07-01 07:00:00

    Scoped equivalent

    To use the monthsAgoStart() method in a scoped application, use the corresponding scoped method: monthsAgoStart().

    GlideSystem - nil(Object obj)

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

    Table 187. Parameters
    Name Type Description
    obj Object The object to be checked.
    Table 188. Returns
    Type Description
    Boolean True if null or empty string; otherwise, false.
    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);
      }
    }

    Scoped equivalent

    To use the nil() method in a scoped application, use the corresponding scoped method: nil().

    GlideSystem - now()

    Returns the current date in UTC.

    Table 189. Parameters
    Name Type Description
    None
    Table 190. 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 now_GR = new GlideRecord("sys_user");
    if (now_GR.get(event.parm1.toString())) {
        // Do something based on the Password Changing
        gs.log("The user password changed so do something else...");
        now_GR.u_password_last_reset = gs.now();
        now_GR.update();
    }

    GlideSystem - nowNoTZ()

    Returns the current date and time in UTC format.

    Table 191. Parameters
    Name Type Description
    None
    Table 192. 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 now_GR = new GlideRecord("sys_user");
    if (now_GR.get(event.parm1.toString())) {
        // Do something based on the Password Changing
        gs.log("The user password changed so do something else...");
        now_GR.u_password_last_reset = gs.nowNoTZ();
        now_GR.update();
    }

    GlideSystem - nowDateTime()

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

    Table 193. Parameters
    Name Type Description
    None
    Table 194. Returns
    Type Description
    String Current date and time in the user-defined format. For more information on setting the system date and time format, see Date and Date/Time fields.
    var currentDateTime = gs.nowDateTime();
    gs.print("Current date/time: " + currentDateTime);
    Output
    Current date/time: 2021-03-17 14:04:02

    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 - nowGlideDateTime()

    Gets a GlideDateTime object with the current date and time.

    After you get a GlideDateTime object with the current date and time, you can use the GlideDateTime methods to perform date-time operations, such as performing date-time calculations, formatting a date-time, or converting between date-time formats.

    Table 195. Parameters
    Name Type Description
    None
    Table 196. Returns
    Type Description
    Object GlideDateTime object with the current date and time in GMT format.

    Sets the field u_target_date to the current date and time in GMT format.

    current.u_target_date = gs.nowGlideDateTime();

    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 197. Parameters
    Name Type Description
    message String The message to log
    Table 198. 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)

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

    Table 199. Parameters
    Name Type Description
    quarters Number Integer number of the quarters ago.
    Table 200. Returns
    Type Description
    String GMT of the quarter that was the specified number of quarters ago.

    Format: yyyy-mm-dd hh:mm:ss

    The following example displays the current date and time and the date and time four quarters ago at the same time.

    var nowDateTime = new GlideDateTime();
    gs.print("Now: " + nowDateTime);
    var fourQuartersAgoDateTime = gs.quartersAgo(4);
    gs.print("Four quarters ago: " + fourQuartersAgoDateTime);

    Output

    Now: 2021-10-20 16:27:32
    Four quarters ago: 2020-10-20 16:27:32

    GlideSystem - quartersAgoEnd(Number quarters)

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

    Table 201. Parameters
    Name Type Description
    quarters Number An integer number of quarters
    Table 202. 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: quartersAgoEnd().

    GlideSystem - quartersAgoStart(Number quarters)

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

    Table 203. Parameters
    Name Type Description
    quarters Number An integer number of quarters
    Table 204. 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: quartersAgoStart().

    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 205. 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 206. Returns
    Type Description
    void
    gs.setProperty("glide.foo","bar","foo");
    gs.info(gs.getProperty("glide.foo"));

    Output: bar

    Scoped equivalent

    To use the setProperty() method in a scoped application, use the corresponding scoped method: setProperty().

    GlideSystem - setRedirect(Object URI)

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

    Table 207. Parameters
    Name Type Description
    URI Object URI to set as the redirect
    Table 208. Returns
    Type Description
    void

    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)

    Scoped equivalent

    To use the setRedirect() method in a scoped application, use the corresponding scoped method: setRedirect().

    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 209. Parameters
    Name Type Description
    URI Object URI to set as the return location.
    Table 210. 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 in the ServiceNow instance.

    Table 211. Parameters
    Name Type Description
    tableName String Name of the table to check.
    Table 212. Returns
    Type Description
    Boolean Flag that indicates whether the specified table exists in the ServiceNow instance.
    Possible values:
    • true: Table exists
    • false: Table does not exist

    This example shows checking whether the incident and foo tables exist in the ServiceNow instance.

    gs.info("Does the incident table exist? " + gs.tableExists("incident"));
    
    gs.info("Does the foo table exist? " + gs.tableExists("foo"));

    Output

    Does the incident table exist? true
    Does the foo table exist? false

    Scoped equivalent

    To use the tableExists() method in a scoped application, use the corresponding scoped method: tableExists().

    GlideSystem - userID()

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

    Table 213. Parameters
    Name Type Description
    None
    Table 214. Returns
    Type Description
    String Sys_id of the current user.

    The following example shows how to unassign all active Incident records assigned to the current user.

    var incidentGR = new GlideRecord('incident');
    incidentGR.addActiveQuery();
    
    // Filter results to incidents assigned to the current user
    var currentUserSysId = gs.userID();
    incidentGR.addQuery('assigned_to', currentUserSysId);
    incidentGR.query();
    
    while (incidentGR.next()) {
        incidentGR.setValue('assigned_to', 'NULL');
        incidentGR.update();
        gs.info(
            'Unassigned Incident: {0}: {1}',
            incidentGR.number.toString(),
            incidentGR.short_description.toString()
        );
    }

    Output:

    Unassigned Incident: INC0000057: Performance problems with wifi
    Unassigned Incident: INC0009001: Unable to post content on a Wiki page
    Unassigned Incident: INC0008111: ATF : Test1

    GlideSystem - workflowFlush(Object glideRecord)

    Deletes any open scheduled job records in the Schedule (sys_trigger) table for the specified GlideRecord.

    Table 215. Parameters
    Name Type Description
    glideRecord Object The GlideRecord
    Table 216. Returns
    Type Description
    void

    GlideSystem - yearsAgo(Number years)

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

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

    To use the yearsAgo(Number years) method in a scoped application, use the corresponding scoped method: yearsAgo(Number years).

    GlideSystem - yesterday()

    Returns yesterday's time (24 hours ago).

    Table 219. Parameters
    Name Type Description
    None
    Table 220. 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: yesterday().