---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideSystem - Global

# GlideSystem - Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 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) {#ariaid-title2}

Adds an error message for the current session.
Use getErrorMessages() to retrieve a list of error messages currently
being shown.
{#r_GS-addErrorMessage_O__table_ug1_qy1_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| message | Object | The message to add. |
[Table 1. Parameters]

{#r_GS-addErrorMessage_O__table_ug1_qy1_mt} {#r_GS-addErrorMessage_O__table_vg1_qy1_mt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 2. Returns]

{#r_GS-addErrorMessage_O__table_vg1_qy1_mt}  

    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 {#r_GS-addErrorMessage_O__section_vhb_mhs_mcb}

To use the addErrorMessage() method in a scoped application, use the
corresponding scoped method: [addErrorMessage()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemAddErrorMessage_Object "Adds an error message for the current session.").

## GlideSystem - addInfoMessage(Object message) {#ariaid-title3}

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.
{#r_GS-addInfoMessage_O__table_it3_2z1_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| message | Object | The message to add. |
[Table 3. Parameters]

{#r_GS-addInfoMessage_O__table_it3_2z1_mt} {#r_GS-addInfoMessage_O__table_jt3_2z1_mt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 4. Returns]

{#r_GS-addInfoMessage_O__table_jt3_2z1_mt}  

    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 {#r_GS-addInfoMessage_O__section_ncj_4hs_mcb}

To use the addInfoMessage() method in a scoped application, use the
corresponding scoped method: [addInfoMessage()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemAddInfoMessage_Object "Adds an info message for the current session. This method is not supported for asynchronous business rules.").

## GlideSystem - addMessage(String type, Object message) {#ariaid-title4}

Adds a message for the current session.
{#r_GS-addMessage_S_O__table_bgw_qz1_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| type | String | Type of message, such as <kbd class="ph userinput">error</kbd> or <kbd class="ph userinput">info</kbd>. |
| message | Object | Message to add to the current session. |
[Table 5. Parameters]

{#r_GS-addMessage_S_O__table_bgw_qz1_mt} {#r_GS-addMessage_S_O__table_cgw_qz1_mt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 6. Returns]

{#r_GS-addMessage_S_O__table_cgw_qz1_mt}  

## GlideSystem - beginningOfLastMonth() {#ariaid-title5}

Gets the date and time for the beginning of last month in GMT.
{#r_GS-beginningOfLastMonth__table_jkt_b5v_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 7. Parameters]

{#r_GS-beginningOfLastMonth__table_jkt_b5v_mt} {#r_GS-beginningOfLastMonth__table_kkt_b5v_mt__entry__2}

| Type | Description |
|-|-|
| String | The GMT beginning of last month, in the format yyyy-mm-dd hh:mm:ss. |
[Table 8. Returns]

{#r_GS-beginningOfLastMonth__table_kkt_b5v_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-beginningOfLastMonth "Returns the date and time for the beginning of last month in GMT.").

## GlideSystem - beginningOfLastWeek() {#ariaid-title6}

Returns the date and time for the beginning of last week in GMT.
{#r_GS-beginningOfLastWeek__table_ngp_m5v_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 9. Parameters]

{#r_GS-beginningOfLastWeek__table_ngp_m5v_mt} {#r_GS-beginningOfLastWeek__table_ogp_m5v_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT beginning of last week. Format: yyyy-mm-dd hh:mm:ss |
[Table 10. Returns]

{#r_GS-beginningOfLastWeek__table_ogp_m5v_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-beginningOfLastWeek "Returns the date and time for the beginning of last week in GMT.").

## GlideSystem - beginningOfNextWeek() {#ariaid-title7}

Returns the date and time for the beginning of next week in GMT.
{#r_GS-beginningOfNextWeek__table_h2f_v5v_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 11. Parameters]

{#r_GS-beginningOfNextWeek__table_h2f_v5v_mt} {#r_GS-beginningOfNextWeek__table_i2f_v5v_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT beginning of next week. Format: yyyy-mm-dd hh:mm:ss |
[Table 12. Returns]

{#r_GS-beginningOfNextWeek__table_i2f_v5v_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemBeginNxtWk "Returns the date and time for the beginning of next week in GMT.").

## GlideSystem - beginningOfNextMonth() {#ariaid-title8}

Returns the date and time for the beginning of next month in GMT.
{#r_GS-beginningOfNextMonth__table_pp1_dvv_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 13. Parameters]

{#r_GS-beginningOfNextMonth__table_pp1_dvv_mt} {#r_GS-beginningOfNextMonth__table_qp1_dvv_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT beginning of next month. Format: yyyy-mm-dd hh:mm:ss |
[Table 14. Returns]

{#r_GS-beginningOfNextMonth__table_qp1_dvv_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-beginningOfNextMonth "Returns the date and time for the beginning of next month in GMT.").

## GlideSystem - beginningOfNextYear() {#ariaid-title9}

Returns the date and time for the beginning of next year in GMT.
{#r_GS-beginningOfNextYear__table_phk_lvv_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 15. Parameters]

{#r_GS-beginningOfNextYear__table_phk_lvv_mt} {#r_GS-beginningOfNextYear__table_qhk_lvv_mt__entry__2}

| Type | Description |
|-|-|
| String | The GMT beginning of next year, in the format yyyy-mm-dd hh:mm:ss. |
[Table 16. Returns]

{#r_GS-beginningOfNextYear__table_qhk_lvv_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-beginningOfNextYear "Returns the date and time for the beginning of next year in GMT.").

## GlideSystem - beginningOfThisMonth() {#ariaid-title10}

Returns the date and time for the beginning of the current month in GMT.
{#r_GS-beginningOfThisMonth__table_mkk_tvv_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 17. Parameters]

{#r_GS-beginningOfThisMonth__table_mkk_tvv_mt} {#r_GS-beginningOfThisMonth__table_nkk_tvv_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT beginning of the current month. Format: yyyy-mm-dd hh:mm:ss |
[Table 18. Returns]

{#r_GS-beginningOfThisMonth__table_nkk_tvv_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-beginningOfThisMonth "Returns the date and time for the beginning of this month in GMT.").

## GlideSystem - beginningOfThisQuarter() {#ariaid-title11}

Returns the date and time for the beginning of the current quarter in GMT.
{#r_GS-beginningOfThisQuarter__table_ts5_1wv_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 19. Parameters]

{#r_GS-beginningOfThisQuarter__table_ts5_1wv_mt} {#r_GS-beginningOfThisQuarter__table_us5_1wv_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT beginning of the current quarter. Format: yyyy-mm-dd hh:mm:ss |
[Table 20. Returns]

{#r_GS-beginningOfThisQuarter__table_us5_1wv_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-beginningOfThisQuarter "Returns the date and time for the beginning of this quarter in GMT.").

## GlideSystem - beginningOfThisWeek() {#ariaid-title12}

Returns the date and time for the beginning of this week in GMT.
{#r_GS-beginningOfThisWeek__table_amj_3wv_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 21. Parameters]

{#r_GS-beginningOfThisWeek__table_amj_3wv_mt} {#r_GS-beginningOfThisWeek__table_bmj_3wv_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT beginning of the current week. Format: yyyy-mm-dd hh:mm:ss |
[Table 22. Returns]

{#r_GS-beginningOfThisWeek__table_bmj_3wv_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-beginningOfThisWeek "Returns the date and time for the beginning of this week in GMT.").

## GlideSystem - beginningOfThisYear() {#ariaid-title13}

Returns the date and time for the beginning of this year in GMT.
{#r_GS-beginningOfThisYear__table_osd_5wv_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 23. Parameters]

{#r_GS-beginningOfThisYear__table_osd_5wv_mt} {#r_GS-beginningOfThisYear__table_psd_5wv_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT beginning of the current year. Format: yyyy-mm-dd hh:mm:ss |
[Table 24. Returns]

{#r_GS-beginningOfThisYear__table_psd_5wv_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-beginningOfThisYear "Returns the date and time for the beginning of this year in GMT.").

## GlideSystem - beginningOfToday() {#ariaid-title14}

Retrieves the date and time for the beginning of today in GMT.
{#r_GS-beginningOfToday__table_vgl_bxv_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 25. Parameters]

{#r_GS-beginningOfToday__table_vgl_bxv_mt} {#r_GS-beginningOfToday__table_wgl_bxv_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT beginning of the current day. Format: yyyy-mm-dd hh:mm:ss |
[Table 26. Returns]

{#r_GS-beginningOfToday__table_wgl_bxv_mt}  
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() {#ariaid-title15}

Retrieves the (UTC) beginning of tomorrow adjusted for the timezone of the current
session.
{#r_GS-beginningOfTomorrow__table_vgl_bxv_dm__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 27. Parameters]

{#r_GS-beginningOfTomorrow__table_vgl_bxv_dm} {#r_GS-beginningOfTomorrow__table_wgl_bxv_dm__entry__2}

| Type | Description |
|-|-|
| String | GMT beginning of tomorrow. Format: yyyy-mm-dd hh:mm:ss |
[Table 28. Returns]

{#r_GS-beginningOfTomorrow__table_wgl_bxv_dm}  

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

## GlideSystem - beginningOfYesterday() {#ariaid-title16}

Retrieves the date and time for the beginning of yesterday in GMT.
{#r_GS-beginningOfYesterday__table_owm_3xv_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 29. Parameters]

{#r_GS-beginningOfYesterday__table_owm_3xv_mt} {#r_GS-beginningOfYesterday__table_pwm_3xv_mt__entry__2}

| Type | Description |
|-|-|
| String | The GMT beginning of yesterday, in the format yyyy-mm-dd hh:mm:ss. |
[Table 30. Returns]

{#r_GS-beginningOfYesterday__table_pwm_3xv_mt}  

    var start = new GlideDateTime();
    start.setValue(gs.beginningOfYesterday());

## GlideSystem - calDateDiff(String startDate, String endDate, Boolean numericValue) {#ariaid-title17}

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](https://servicenow-prod.fluidtopics.net/Um6XIFc1jXn1t9ifoqedMg#c_UsefulSchedulingScripts "A business rule script specifies the actions that the business rule takes. Scripts commonly include predefined global variables to reference items in your system, such as the current record. Global variables are available to all business rules.").
{#r_GS-calDateDiff_S_S_B__table_ulx_gyv_mt__entry__3}

| 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 31. Parameters]

{#r_GS-calDateDiff_S_S_B__table_ulx_gyv_mt} {#r_GS-calDateDiff_S_S_B__table_vlx_gyv_mt__entry__2}

| 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. |
[Table 32. Returns]

{#r_GS-calDateDiff_S_S_B__table_vlx_gyv_mt}  

    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) {#ariaid-title18}

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().
{#r_GS-dateDiff_S_S_B__table_t5n_2zv_mt__entry__3}

| 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 33. Parameters]

{#r_GS-dateDiff_S_S_B__table_t5n_2zv_mt} {#r_GS-dateDiff_S_S_B__table_u5n_2zv_mt__entry__2}

| 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. |
[Table 34. Returns]

{#r_GS-dateDiff_S_S_B__table_u5n_2zv_mt}  

    // 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) {#ariaid-title19}

Generates a date and time for the specified date in GMT.
{#r_GS-dateGenerate_S_S__table_ghf_3jw_mt__entry__3}

| 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 35. Parameters]

{#r_GS-dateGenerate_S_S__table_ghf_3jw_mt} {#r_GS-dateGenerate_S_S__table_hhf_3jw_mt__entry__2}

| Type | Description |
|-|-|
| String | Generated date and time. If the range is <kbd class="ph userinput">start</kbd>, the returned value is yyyy-mm-dd 00:00:00. If range is <kbd class="ph userinput">end</kbd> the return value is yyyy-mm-dd 23:59:59. Format: yyyy-mm-dd hh:mm:ss |
[Table 36. Returns]

{#r_GS-dateGenerate_S_S__table_hhf_3jw_mt}  
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 {#r_GS-dateGenerate_S_S__section_zcf_gg5_y4b}

To use the dateGenerate() method in a scoped application, use the
corresponding scoped method: [dateGenerate()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_SGSYS-dateGenerate_S_S "Generates a date and time for the specified date in GMT.").

## GlideSystem - daysAgo(Number days) {#ariaid-title20}

Returns a date and time for a certain number of days ago.
{#r_GS-daysAgo_N__table_vlc_zjw_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| days | Number | Number of days |
[Table 37. Parameters]

{#r_GS-daysAgo_N__table_vlc_zjw_mt} {#r_GS-daysAgo_N__table_wlc_zjw_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT of the specified number of days ago. Format: yyyy-mm-dd hh:mm:ss. |
[Table 38. Returns]

{#r_GS-daysAgo_N__table_wlc_zjw_mt}  

    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 {#r_GS-daysAgo_N__section_c1p_m3s_mcb}

To use the daysAgo() method in a scoped application, use the
corresponding scoped method: [daysAgo()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-daysAgo_N "Returns the date and time for a specified number of days ago.").

## GlideSystem - daysAgoEnd(Number days) {#ariaid-title21}

Returns a date and time for the end of the day a specified number of days
ago.
{#r_GS-daysAgoEnd_N__table_umn_mkw_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| days | Number | Integer number of days |
[Table 39. Parameters]

{#r_GS-daysAgoEnd_N__table_umn_mkw_mt} {#r_GS-daysAgoEnd_N__table_vmn_mkw_mt__entry__2}

| Type | Description |
|-|-|
| String | The GMT end of the day in the format yyyy-mm-dd hh:mm:ss. |
[Table 40. Returns]

{#r_GS-daysAgoEnd_N__table_vmn_mkw_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-daysAgoEnd_N "Returns the date and time for the end of the day a specified number of days ago.").

## GlideSystem - daysAgoLocal(Number days) {#ariaid-title22}

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).
{#GS-daysAgoLocal_N__table_cvk_ktw_v1b__entry__3}

| Name | Type | Description |
|-|-|-|
| days | Number | Number of days ago |
[Table 41. Parameters]

{#GS-daysAgoLocal_N__table_cvk_ktw_v1b} {#GS-daysAgoLocal_N__table_dvk_ktw_v1b__entry__2}

| 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. |
[Table 42. Returns]

{#GS-daysAgoLocal_N__table_dvk_ktw_v1b}  

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

## GlideSystem - daysAgoStart(Number days) {#ariaid-title23}

Returns a date and time for the beginning of the day a specified number of days
ago.
{#r_GS-daysAgoStart_N__table_xlm_ykw_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| days | String | Integer number of days |
[Table 43. Parameters]

{#r_GS-daysAgoStart_N__table_xlm_ykw_mt} {#r_GS-daysAgoStart_N__table_ylm_ykw_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT start of the day in the format yyyy-mm-dd hh:mm:ss |
[Table 44. Returns]

{#r_GS-daysAgoStart_N__table_ylm_ykw_mt}  

    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 {#r_GS-daysAgoStart_N__section_xf3_k3s_mcb}

To use the daysAgoStart() method in a scoped application, use the
corresponding scoped method: [daysAgoStart()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-daysAgoStart_N "Returns the date and time for the beginning of the day a specified number of days ago.").

## GlideSystem - endOfLastMonth() {#ariaid-title24}

Returns the date and time for the end of last month in GMT.
{#r_GS-endOfLastMonth__table_ef1_jlw_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 45. Parameters]

{#r_GS-endOfLastMonth__table_ef1_jlw_mt} {#r_GS-endOfLastMonth__table_ff1_jlw_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT of the end of last month. Format: yyyy-mm-dd hh:mm:ss |
[Table 46. Returns]

{#r_GS-endOfLastMonth__table_ff1_jlw_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-endOfLastMonth "Returns the date and time for the end of last month in GMT.").

## GlideSystem - endOfLastWeek() {#ariaid-title25}

Returns the date and time for the end of last week in GMT.
{#r_GS-endOfLastWeek__table_mth_qlw_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 47. Parameters]

{#r_GS-endOfLastWeek__table_mth_qlw_mt} {#r_GS-endOfLastWeek__table_nth_qlw_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT end of last week. Format: yyyy-mm-dd hh:mm:ss |
[Table 48. Returns]

{#r_GS-endOfLastWeek__table_nth_qlw_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-endOfLastWeek "Returns the date and time for the end of last week in GMT.").

## GlideSystem - endOfLastYear() {#ariaid-title26}

Returns the date and time for the end of last year in GMT.
{#r_GS-endOfLastYear__table_rzh_pww_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 49. Parameters]

{#r_GS-endOfLastYear__table_rzh_pww_mt} {#r_GS-endOfLastYear__table_szh_pww_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT in format yyyy-mm-dd hh:mm:ss. |
[Table 50. Returns]

{#r_GS-endOfLastYear__table_szh_pww_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-endOfLastYear "Returns the date and time for the end of last year in GMT.").

## GlideSystem - endOfNextMonth() {#ariaid-title27}

Returns the date and time for the end of next month in GMT.
{#r_GS-endOfNextMonth__table_cpz_xww_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 51. Parameters]

{#r_GS-endOfNextMonth__table_cpz_xww_mt} {#r_GS-endOfNextMonth__table_dpz_xww_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT data and time. Format yyyy-mm-dd hh:mm:ss |
[Table 52. Returns]

{#r_GS-endOfNextMonth__table_dpz_xww_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-endOfNextMonth "Returns the date and time for the end of next month in GMT.").

## GlideSystem - endOfNextWeek() {#ariaid-title28}

Returns the date and time for the end of next week in GMT.
{#r_GS-endOfNextWeek__table_c2q_kxw_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 53. Parameters]

{#r_GS-endOfNextWeek__table_c2q_kxw_mt} {#r_GS-endOfNextWeek__table_d2q_kxw_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT date and time for the end of next week. Format yyyy-mm-dd hh:mm:ss |
[Table 54. Returns]

{#r_GS-endOfNextWeek__table_d2q_kxw_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemEofNW "Returns the date and time for the end of next week in GMT.").

## GlideSystem - endOfNextYear() {#ariaid-title29}

Returns the date and time for the end of next year in GMT.
{#r_GS-endOfNextYear__table_u3w_rxw_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 55. Parameters]

{#r_GS-endOfNextYear__table_u3w_rxw_mt} {#r_GS-endOfNextYear__table_v3w_rxw_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT date and time for the end of next year. Format: yyyy-mm-dd hh:mm:ss |
[Table 56. Returns]

{#r_GS-endOfNextYear__table_v3w_rxw_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-endOfNextYear "Returns the date and time for the end of next year in GMT.").

## GlideSystem - endOfThisMonth() {#ariaid-title30}

Returns the date and time for the end of this month in GMT.
{#r_GS-endOfThisMonth__table_bky_lyw_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 57. Parameters]

{#r_GS-endOfThisMonth__table_bky_lyw_mt} {#r_GS-endOfThisMonth__table_cky_lyw_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT date and time for the end of this month. Format yyyy-mm-dd hh:mm:ss |
[Table 58. Returns]

{#r_GS-endOfThisMonth__table_cky_lyw_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-endOfThisMonth "Returns the date and time for the end of this month in GMT.").

## GlideSystem - endOfThisQuarter() {#ariaid-title31}

Returns the date and time for the end of this quarter in GMT.
{#r_GS-endOfThisQuarter__table_ijn_5yw_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 59. Parameters]

{#r_GS-endOfThisQuarter__table_ijn_5yw_mt} {#r_GS-endOfThisQuarter__table_jjn_5yw_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT date and time for the end of this quarter. Format: yyyy-mm-dd hh:mm:ss |
[Table 60. Returns]

{#r_GS-endOfThisQuarter__table_jjn_5yw_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-endOfThisQuarter "Returns the date and time for the end of this quarter in GMT.").

## GlideSystem - endOfThisWeek() {#ariaid-title32}

Returns the date and time for the end of this week in GMT.
{#r_GS-endOfThisWeek__table_jqb_czw_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 61. Parameters]

{#r_GS-endOfThisWeek__table_jqb_czw_mt} {#r_GS-endOfThisWeek__table_kqb_czw_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT date and time for the end of this week. Format: yyyy-mm-dd hh:mm:ss |
[Table 62. Returns]

{#r_GS-endOfThisWeek__table_kqb_czw_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-endOfThisWeek "Returns the date and time for the end of this week in GMT.").

## GlideSystem - endOfThisYear() {#ariaid-title33}

Returns the date and time for the end of this year in GMT.
{#r_GS-endOfThisYear__table_ayg_4zw_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 63. Parameters]

{#r_GS-endOfThisYear__table_ayg_4zw_mt} {#r_GS-endOfThisYear__table_byg_4zw_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT date and time for the end of this year. Format yyyy-mm-dd hh:mm:ss |
[Table 64. Returns]

{#r_GS-endOfThisYear__table_byg_4zw_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-endOfThisYear "Returns the date and time for the end of this year in GMT.").

## GlideSystem - endOfToday() {#ariaid-title34}

Retrieves the date and time for the end of today in GMT.
{#r_GS-endOfToday__table_hy4_vzw_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 65. Parameters]

{#r_GS-endOfToday__table_hy4_vzw_mt} {#r_GS-endOfToday__table_iy4_vzw_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT in the format yyyy-mm-dd hh:mm:ss. |
[Table 66. Returns]

{#r_GS-endOfToday__table_iy4_vzw_mt}  

    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() {#ariaid-title35}

Retrieves the date and time for the end of tomorrow in GMT.
{#r_GS-endOfTomorrow__table_hy4_vzw_xy__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 67. Parameters]

{#r_GS-endOfTomorrow__table_hy4_vzw_xy} {#r_GS-endOfTomorrow__table_iy4_vzw_zx__entry__2}

| Type | Description |
|-|-|
| String | GMT in the format yyyy-mm-dd hh:mm:ss. |
[Table 68. Returns]

{#r_GS-endOfTomorrow__table_iy4_vzw_zx}  

    var tomorrowEnd = new GlideDateTime();
    tomorrowEnd.setValue(gs.endOfTomorrow());

## GlideSystem - endOfYesterday() {#ariaid-title36}

Gets the date and time for the end of yesterday in GMT.
{#r_GS-endOfYesterday__table_lyt_c1x_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 69. Parameters]

{#r_GS-endOfYesterday__table_lyt_c1x_mt} {#r_GS-endOfYesterday__table_myt_c1x_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT in the format (yyyy-mm-dd huh:mm:ss). |
[Table 70. Returns]

{#r_GS-endOfYesterday__table_myt_c1x_mt}  

    var yesterdayEnd = new GlideDateTime();
    yesterdayEnd.setValue(gs.endOfYesterday());

## GlideSystem - eventQueue(String name, Object glideRecord, String parm1, String parm2,
String queue) {#ariaid-title37}

Queues an event for the event manager.
{#r_GS-eventQueue_S_O_S_S_S__table_pkj_nf5_lt__entry__3}

| 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 71. Parameters]

{#r_GS-eventQueue_S_O_S_S_S__table_pkj_nf5_lt} {#r_GS-eventQueue_S_O_S_S_S__table_qkj_nf5_lt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 72. Returns]

{#r_GS-eventQueue_S_O_S_S_S__table_qkj_nf5_lt}  

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

### Scoped equivalent {#r_GS-eventQueue_S_O_S_S_S__section_hlh_hjs_mcb}

To use the eventQueue() method in a scoped application, use the
corresponding scoped method: [eventQueue()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemEventQueue_String_Object_String_String_String "Queues an event for the event manager.").

## GlideSystem - eventQueueScheduled(String name, Object glideRecord, String parm1, String
parm2, Object expiration) {#ariaid-title38}

Queues an event for the event manager at a specified date and time.
{#GS-eventQueueScheduled_S_O_S_S_O__table_yb2_qsy_h2b__entry__3}

| 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 73. Parameters]

{#GS-eventQueueScheduled_S_O_S_S_O__table_yb2_qsy_h2b} {#GS-eventQueueScheduled_S_O_S_S_O__table_zb2_qsy_h2b__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 74. Returns]

{#GS-eventQueueScheduled_S_O_S_S_O__table_zb2_qsy_h2b}  

    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 {#GS-eventQueueScheduled_S_O_S_S_O__section_hlh_hjs_mcb}

To use the eventQueueScheduled() method in a scoped application, use the
corresponding scoped method: [eventQueueScheduled()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_SGSYS-eventQSched_S_O_S_S_O "Queues an event in the event manager.").

## GlideSystem - flushMessages() {#ariaid-title39}

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.
{#r_GS-flushMessages__table_nzn_c1b_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 75. Parameters]

{#r_GS-flushMessages__table_nzn_c1b_mt} {#r_GS-flushMessages__table_ozn_c1b_mt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 76. Returns]

{#r_GS-flushMessages__table_ozn_c1b_mt}  
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() {#ariaid-title40}

Returns the file path to the user's avatar.
{#r_GlideSystemGetAvatar__table_hwf_qt5_ts__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 77. Parameters]

{#r_GlideSystemGetAvatar__table_hwf_qt5_ts} {#r_GlideSystemGetAvatar__table_iwf_qt5_ts__entry__2}

| Type | Description |
|-|-|
| String | The file path to the user's avatar. |
[Table 78. Returns]

{#r_GlideSystemGetAvatar__table_iwf_qt5_ts}  

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

Output:

    User avatar ID: c148e1d13741310042106710ce41f149.iix?t=small

## GlideSystem - getCurrentScopeName() {#ariaid-title41}

Returns the name of the current application scope.
{#r_GS-getCurrentScopeName__table_hkd_pg5_lt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 79. Parameters]

{#r_GS-getCurrentScopeName__table_hkd_pg5_lt} {#r_GS-getCurrentScopeName__table_ikd_pg5_lt__entry__2}

| Type | Description |
|-|-|
| String | Current scope name. |
[Table 80. Returns]

{#r_GS-getCurrentScopeName__table_ikd_pg5_lt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemGetCurrentScopeName "Gets the name of the current scope.").

## GlideSystem - getDateFormat() {#ariaid-title42}

Returns the date format associated with the current user.
{#GS-getDateFormat_S__table_lwb_dw4_m5b__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 81. Parameters]

{#GS-getDateFormat_S__table_lwb_dw4_m5b} {#GS-getDateFormat_S__table_mwb_dw4_m5b__entry__2}

| Type | Description |
|-|-|
| String | The date format associated with the current user. |
[Table 82. Returns]

{#GS-getDateFormat_S__table_mwb_dw4_m5b}  
The following example returns the date format associated with the user.

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

Output:

    yyyy-MM-dd

## GlideSystem - getDateTimeFormat() {#ariaid-title43}

Returns the date and time format associated with the current user.
{#GS-getDateTimeFormat_S__table_lcm_2np_m5b__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 83. Parameters]

{#GS-getDateTimeFormat_S__table_lcm_2np_m5b} {#GS-getDateTimeFormat_S__table_mcm_2np_m5b__entry__2}

| Type | Description |
|-|-|
| String | The date and time format associated with the current user. |
[Table 84. Returns]

{#GS-getDateTimeFormat_S__table_mcm_2np_m5b}  
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) {#ariaid-title44}

Retrieves the display column for the table.
{#r_GS-getDisplayColumn_S__table_wp5_bh5_lt__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | Name of the table from which to get the display column name. |
[Table 85. Parameters]

{#r_GS-getDisplayColumn_S__table_wp5_bh5_lt} {#r_GS-getDisplayColumn_S__table_xp5_bh5_lt__entry__2}

| Type | Description |
|-|-|
| String | Display column name |
[Table 86. Returns]

{#r_GS-getDisplayColumn_S__table_xp5_bh5_lt}  

    // 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) {#ariaid-title45}

Returns the display value for a specified field on a specified record.
{#r_GS-getDisplayValueFor_S_S_S__table_ic1_th5_lt__entry__3}

| 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 87. Parameters]

{#r_GS-getDisplayValueFor_S_S_S__table_ic1_th5_lt} {#r_GS-getDisplayValueFor_S_S_S__table_jc1_th5_lt__entry__2}

| Type | Description |
|-|-|
| String | Display value for the field. |
[Table 88. Returns]

{#r_GS-getDisplayValueFor_S_S_S__table_jc1_th5_lt}  
This example shows how to use getDisplayValueFor() to return the display
value of the <var class="keyword varname">number</var> field.

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

## GlideSystem - getErrorMessages() {#ariaid-title46}

Returns the list of error messages for the session that were added by
addErrorMessage().
{#r_GS-getErrorMessages__table_kdg_q1b_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 89. Parameters]

{#r_GS-getErrorMessages__table_kdg_q1b_mt} {#r_GS-getErrorMessages__table_ldg_q1b_mt__entry__2}

| Type | Description |
|-|-|
| String | List of error messages |
[Table 90. Returns]

{#r_GS-getErrorMessages__table_ldg_q1b_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-getErrorMessages "Returns the error messages that were added by addErrorMessage() for the session.").

## GlideSystem - getEscapedProperty(String key, Object substituteObject) {#ariaid-title47}

Retrieves the property and escapes it for XML parsing.
{#r_GS-getEscapedProperty_S_O__table_gj5_l35_lt__entry__3}

| 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 91. Parameters]

{#r_GS-getEscapedProperty_S_O__table_gj5_l35_lt} {#r_GS-getEscapedProperty_S_O__table_hj5_l35_lt__entry__2}

| Type | Description |
|-|-|
| String | Property, or the substituteObject if the property is not found. |
[Table 92. Returns]

{#r_GS-getEscapedProperty_S_O__table_hj5_l35_lt}  

    var propValue = gs.getEscapedProperty("com.example.my_test_property");
    gs.addInfoMessage("This is my property value " + propValue);

## GlideSystem - getImpersonatingUserDisplayName() {#ariaid-title48}

Returns the display name of the impersonating user.
{#r_GS-getImpersonatingUserDispName__table_jlq_fbb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 93. Parameters]

{#r_GS-getImpersonatingUserDispName__table_jlq_fbb_mt} {#r_GS-getImpersonatingUserDispName__table_klq_fbb_mt__entry__2}

| Type | Description |
|-|-|
| String | Display name of the impersonating user. |
[Table 94. Returns]

{#r_GS-getImpersonatingUserDispName__table_klq_fbb_mt}  
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() {#ariaid-title49}

Returns the name of the impersonating user or null if not impersonating.
{#r_GS-getImpersonatingUserName__table_u4p_nfb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 95. Parameters]

{#r_GS-getImpersonatingUserName__table_u4p_nfb_mt} {#r_GS-getImpersonatingUserName__table_v4p_nfb_mt__entry__2}

| Type | Description |
|-|-|
| String | Name of impersonating user |
[Table 96. Returns]

{#r_GS-getImpersonatingUserName__table_v4p_nfb_mt}  
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() {#ariaid-title50}

Retrieves the list of info messages for the session that were added by
addInfoMessage().
{#r_GS-getInfoMessages__table_tw1_wfb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 97. Parameters]

{#r_GS-getInfoMessages__table_tw1_wfb_mt} {#r_GS-getInfoMessages__table_uw1_wfb_mt__entry__2}

| Type | Description |
|-|-|
| String | List of info messages. |
[Table 98. Returns]

{#r_GS-getInfoMessages__table_uw1_wfb_mt}  
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() {#ariaid-title51}

Returns the user's initials.
{#r_GlideSystemGetInitials__table_dvl_j55_ts__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 99. Parameters]

{#r_GlideSystemGetInitials__table_dvl_j55_ts} {#r_GlideSystemGetInitials__table_evl_j55_ts__entry__2}

| Type | Description |
|-|-|
| String | The user's initials. |
[Table 100. Returns]

{#r_GlideSystemGetInitials__table_evl_j55_ts}  

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

Output:

    User initials: SA

## GlideSystem - getMessage(String messageID, Object args) {#ariaid-title52}

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](https://www.servicenow.com/docs/access?context=r_MessageTable&version=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US).  
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).
{#r_GS-getMessage_S_O__table_czl_5j5_lt__entry__3}

| 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 <var class="keyword varname">'{0}'</var> is replaced with the content of <var class="keyword varname">current.action.name</var>. Note: The passed in values are not translated. They are inserted verbatim in the message. |
[Table 101. Parameters]

{#r_GS-getMessage_S_O__table_czl_5j5_lt} {#r_GS-getMessage_S_O__table_dzl_5j5_lt__entry__2}

| Type | Description |
|-|-|
| String | Requested UI message. |
[Table 102. Returns]

{#r_GS-getMessage_S_O__table_dzl_5j5_lt}  
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 {#r_GS-getMessage_S_O__section_tvw_3qs_mcb}

To use the getMessage() method in a scoped application, use the
corresponding scoped method: [getMessage()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemGetMessage_String_Object "Retrieves translated messages from the Message [sys_ui_message] table to display in a UI.").

## GlideSystem - getMessageS(String messageID, Object args) {#ariaid-title53}

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](https://www.servicenow.com/docs/access?context=r_MessageTable&version=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US).

Useful if you are inserting into a JavaScript expression from Jelly.
{#r_GS-getMessageS_S_O__table_gyt_xk5_lt__entry__3}

| 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 <var class="keyword varname">'{0}'</var> is replaced with the content of <var class="keyword varname">current.action.name</var>. Note: The passed in values are not translated. They are inserted verbatim in the message. |
[Table 103. Parameters]

{#r_GS-getMessageS_S_O__table_gyt_xk5_lt} {#r_GS-getMessageS_S_O__table_hyt_xk5_lt__entry__2}

| Type | Description |
|-|-|
| String | Specified message with ticks escaped. |
[Table 104. Returns]

{#r_GS-getMessageS_S_O__table_hyt_xk5_lt}  

    /*
    "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) {#ariaid-title54}

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.
{#GS-getMessageLang_S_S_O__table_m4v_3tl_zyb__entry__3}

| 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 <var class="keyword varname">'{0}'</var> is replaced with the content of <var class="keyword varname">current.action.name</var>. Note: The passed in values are not translated. They are inserted verbatim in the message. |
[Table 105. Parameters]

{#GS-getMessageLang_S_S_O__table_m4v_3tl_zyb} {#GS-getMessageLang_S_S_O__table_n4v_3tl_zyb__entry__2}

| Type | Description |
|-|-|
| String | Translated message. |
[Table 106. Returns]

{#GS-getMessageLang_S_S_O__table_n4v_3tl_zyb}  
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) {#ariaid-title55}

Returns the node name for the specified index.
{#r_GS-getNodeName_O_N__table_mqs_3hb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| obj | Object | Object to examine. |
| index | Number | Index from which to obtain the node name. |
[Table 107. Parameters]

{#r_GS-getNodeName_O_N__table_mqs_3hb_mt} {#r_GS-getNodeName_O_N__table_nqs_3hb_mt__entry__2}

| Type | Description |
|-|-|
| String | Node's name |
[Table 108. Returns]

{#r_GS-getNodeName_O_N__table_nqs_3hb_mt}  

    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) {#ariaid-title56}

Returns the node value for the specified index.
{#r_GS-getNodeValue_O_N__table_cxv_5gb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| obj | Object | Object to examine. |
| index | Number | Index from which to get the node valu.e |
[Table 109. Parameters]

{#r_GS-getNodeValue_O_N__table_cxv_5gb_mt} {#r_GS-getNodeValue_O_N__table_dxv_5gb_mt__entry__2}

| Type | Description |
|-|-|
| Object | Node value |
[Table 110. Returns]

{#r_GS-getNodeValue_O_N__table_dxv_5gb_mt}  

    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) {#ariaid-title57}

Returns the specified user preference.
{#r_GS-getPreference_S_O__table_vz2_vhb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| key | String | Key for the preference. |
| default | Object | Default value to use if the specified preference is not found. |
[Table 111. Parameters]

{#r_GS-getPreference_S_O__table_vz2_vhb_mt} {#r_GS-getPreference_S_O__table_wz2_vhb_mt__entry__2}

| Type | Description |
|-|-|
| String | Preference value. If no preference, returns the specified default value. |
[Table 112. Returns]

{#r_GS-getPreference_S_O__table_wz2_vhb_mt}  

    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) {#ariaid-title58}

Returns the value of a Glide property. If the property is not found, returns the
specified alt value.
{#r_GS-getProperty_S_O__table_s2k_ns1_mt__entry__3}

| 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 113. Parameters]

{#r_GS-getProperty_S_O__table_s2k_ns1_mt} {#r_GS-getProperty_S_O__table_t2k_ns1_mt__entry__2}

| Type | Description |
|-|-|
| String | Value of the Glide property, or the alternate object defined above. |
[Table 114. Returns]

{#r_GS-getProperty_S_O__table_t2k_ns1_mt}  

    //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) {#ariaid-title59}

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.
{#r_GS-getScriptError_S__table_p35_dt1_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| script | String | Script to check for errors. |
[Table 115. Parameters]

{#r_GS-getScriptError_S__table_p35_dt1_mt} {#r_GS-getScriptError_S__table_q35_dt1_mt__entry__2}

| Type | Description |
|-|-|
| String | Error message. Null if there is no error. |
[Table 116. Returns]

{#r_GS-getScriptError_S__table_q35_dt1_mt}  

    if (gs.isValidScript(current.script) == false)
      {
        current.setAbortAction(true);
        var error = gs.getScriptError(current.script);
        current.script.setError(error);
      }

## GlideSystem - getSession() {#ariaid-title60}

Returns a GlideSession object.
{#r_GS-getSession__table_k2k_j3b_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 117. Parameters]

{#r_GS-getSession__table_k2k_j3b_mt} {#r_GS-getSession__table_l2k_j3b_mt__entry__2}

| Type | Description |
|-|-|
| GlideSession Object | GlideSession object for the current session |
[Table 118. Returns]

{#r_GS-getSession__table_l2k_j3b_mt}  

    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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemGetSession "Gets a reference to the current Glide session.").

## GlideSystem - getSessionID() {#ariaid-title61}

Returns the GlideSession session ID.
{#r_GS-getSessionID__table_z31_t3b_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 119. Parameters]

{#r_GS-getSessionID__table_z31_t3b_mt} {#r_GS-getSessionID__table_aj1_t3b_mt__entry__2}

| Type | Description |
|-|-|
| String | Session ID |
[Table 120. Returns]

{#r_GS-getSessionID__table_aj1_t3b_mt}  

    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](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemGetSessionID "Retrieves the GlideSession session ID.").

## GlideSystem - getStyle(String tableName, String fieldName, String fieldValue) {#ariaid-title62}

Returns the style defined for the table, field, and field value.
{#r_GS-getStyle_S_S_S__table_pgz_rt1_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | Table name |
| fieldName | String | Field name |
| fieldValue | String | Field value |
[Table 121. Parameters]

{#r_GS-getStyle_S_S_S__table_pgz_rt1_mt} {#r_GS-getStyle_S_S_S__table_qgz_rt1_mt__entry__2}

| Type | Description |
|-|-|
| String | Style of the specified field. |
[Table 122. Returns]

{#r_GS-getStyle_S_S_S__table_qgz_rt1_mt}  

    var returnString = gs.getStyle('<tableName>', '<fieldName>', '<fieldValue>');
    gs.print(returnString);

## GlideSystem - getTimeFormat() {#ariaid-title63}

Returns the time format associated with the current user.
{#GS-getTimeFormat_S__table_j1c_bht_q5b__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 123. Parameters]

{#GS-getTimeFormat_S__table_j1c_bht_q5b} {#GS-getTimeFormat_S__table_k1c_bht_q5b__entry__2}

| Type | Description |
|-|-|
| String | The time format associated with the current user. |
[Table 124. Returns]

{#GS-getTimeFormat_S__table_k1c_bht_q5b}  

    var userTimeFormat = gs. getTimeFormat();
    gs.info(userTimeFormat);

Output:

    HH:mm:ss

## GlideSystem - getUser() {#ariaid-title64}

Returns a reference to the user object for the current user.
{#r_GS-getUser__table_ed5_hjb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 125. Parameters]

{#r_GS-getUser__table_ed5_hjb_mt} {#r_GS-getUser__table_fd5_hjb_mt__entry__2}

| Type | Description |
|-|-|
| GlideUser | Reference to a user object for the current user. |
[Table 126. Returns]

{#r_GS-getUser__table_fd5_hjb_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemGetUser "Returns a reference to the scoped GlideUser object for the current user.").

## GlideSystem - getUserDisplayName() {#ariaid-title65}

Gets the display name of the current user.
{#r_GS-getUserDisplayName__table_mvv_vjb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 127. Parameters]

{#r_GS-getUserDisplayName__table_mvv_vjb_mt} {#r_GS-getUserDisplayName__table_nvv_vjb_mt__entry__2}

| Type | Description |
|-|-|
| String | The name field of the current user. For example, this method returns Abel Tuter as opposed to abel.tuter. |
[Table 128. Returns]

{#r_GS-getUserDisplayName__table_nvv_vjb_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemGetUserDisplayName "Gets the display name of the current user.").

## GlideSystem - getUserID() {#ariaid-title66}

Returns the sys_id of the current user.
{#r_GS-getUserID__table_o5c_kkb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 129. Parameters]

{#r_GS-getUserID__table_o5c_kkb_mt} {#r_GS-getUserID__table_p5c_kkb_mt__entry__2}

| Type | Description |
|-|-|
| String | Sys_id of the current user. |
[Table 130. Returns]

{#r_GS-getUserID__table_p5c_kkb_mt}  
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 {#r_GS-getUserID__section_uw1_nrs_mcb}

To use the getUserID() method in a scoped application, use the
corresponding scoped method: [getUserID()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemGetUserID "Gets the sys_id of the current user.").

## GlideSystem - getUserName() {#ariaid-title67}

Returns the user name of the current user.
{#r_GS-getUserName__table_apf_plb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 131. Parameters]

{#r_GS-getUserName__table_apf_plb_mt} {#r_GS-getUserName__table_bpf_plb_mt__entry__2}

| Type | Description |
|-|-|
| String | The user name of the current user. For example, this method returns abel.tuter as opposed to Abel Tuter. |
[Table 132. Returns]

{#r_GS-getUserName__table_bpf_plb_mt}  
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 {#r_GS-getUserName__section_cm2_prs_mcb}

To use the getUserName() method in a scoped application, use the
corresponding scoped method: [getUserName()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemGetUserName "Returns the user name of the current user.").

## GlideSystem - getUserNameByUserID(String user_id) {#ariaid-title68}

Returns the user display name based on a provided user login name.
{#r_GS-getUserNameByUserID_S__table_op4_1mb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| user_id | String | Login name of the user from which to retrieve the associated display name. |
[Table 133. Parameters]

{#r_GS-getUserNameByUserID_S__table_op4_1mb_mt} {#r_GS-getUserNameByUserID_S__table_pp4_1mb_mt__entry__2}

| 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. |
[Table 134. Returns]

{#r_GS-getUserNameByUserID_S__table_pp4_1mb_mt}  
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) {#ariaid-title69}

Constructs an array of all the nodes and values in an XML document.
{#r_GS-getXMLNodeList_S__table_tsq_jnb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| xml | String | XML document to parse. |
[Table 135. Parameters]

{#r_GS-getXMLNodeList_S__table_tsq_jnb_mt} {#r_GS-getXMLNodeList_S__table_usq_jnb_mt__entry__2}

| Type | Description |
|-|-|
| Array list | List of names and values of the outer most XML node. |
[Table 136. Returns]

{#r_GS-getXMLNodeList_S__table_usq_jnb_mt}  
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) {#ariaid-title70}

Returns the XML text for the first element in the XML string that matches the XPath
query.
{#r_GS-getXMLText_S_S__table_zmk_lmb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| xml | String | XML string to search. |
| xpathQuery | String | XPath query to match. |
[Table 137. Parameters]

{#r_GS-getXMLText_S_S__table_zmk_lmb_mt} {#r_GS-getXMLText_S_S__table_ank_lmb_mt__entry__2}

| Type | Description |
|-|-|
| String | XML node matching the search parameters. |
[Table 138. Returns]

{#r_GS-getXMLText_S_S__table_ank_lmb_mt}  
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) {#ariaid-title71}

Determines if the current user has at least one of the passed-in roles.
{#r_GS-hasRole_S__table_byk_5nb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| roleName | String | Comma-separated list of roles. |
[Table 139. Parameters]

{#r_GS-hasRole_S__table_byk_5nb_mt} {#r_GS-hasRole_S__table_cyk_5nb_mt__entry__2}

| 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. {#r_GS-hasRole_S__ul_twc_kpj_z4b} |
[Table 140. Returns]

{#r_GS-hasRole_S__table_cyk_5nb_mt}  
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 {#r_GS-hasRole_S__section_ex4_rrs_mcb}

To use the hasRole() method in a scoped application, use the
corresponding scoped method: [hasRole()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemHasRole_Object "Determines if the current user has the specified role.").

## GlideSystem - hasRoleInGroup(Object roleName, Object group) {#ariaid-title72}

Determines if the current user has the specified role within a specified
group.
{#r_GS-hasRoleInGroup_O_O__table_dys_m4b_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| roleName | Object | Name of the role. |
| group | Object | Sys_id of the group to check for the specified role. |
[Table 141. Parameters]

{#r_GS-hasRoleInGroup_O_O__table_dys_m4b_mt} {#r_GS-hasRoleInGroup_O_O__table_eys_m4b_mt__entry__2}

| 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. {#r_GS-hasRoleInGroup_O_O__ul_twc_kpj_z4b} |
[Table 142. Returns]

{#r_GS-hasRoleInGroup_O_O__table_eys_m4b_mt}  
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) {#ariaid-title73}

Returns a date and time for the specified number of hours ago. The returned value is
adjusted for the time zone of the instance.
{#r_GS-hoursAgo_N__table_vrq_j1x_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| hours | Number | Number of hours ago. |
[Table 143. Parameters]

{#r_GS-hoursAgo_N__table_vrq_j1x_mt} {#r_GS-hoursAgo_N__table_wrq_j1x_mt__entry__2}

| Type | Description |
|-|-|
| String | UTC date and time for the specified number of hours ago. Format: yyyy-mm-dd hh:mm:ss |
[Table 144. Returns]

{#r_GS-hoursAgo_N__table_wrq_j1x_mt}  

    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 {#r_GS-hoursAgo_N__section_usc_xrs_mcb}

To use the hoursAgo() method in a scoped application, use the
corresponding scoped method: [hoursAgo()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-hoursAgo_N "Returns the date and time for a specified number of hours ago.").

## GlideSystem - hoursAgoEnd(Number hours) {#ariaid-title74}

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.
{#r_GS-hoursAgoEnd_N__table_ddc_v1x_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| hours | Number (Integer) | Number of hours ago. |
[Table 145. Parameters]

{#r_GS-hoursAgoEnd_N__table_ddc_v1x_mt} {#r_GS-hoursAgoEnd_N__table_edc_v1x_mt__entry__2}

| Type | Description |
|-|-|
| String | UTC date and time for the end of the specified number of hours ago. Format: yyyy-mm-dd hh:mm:ss |
[Table 146. Returns]

{#r_GS-hoursAgoEnd_N__table_edc_v1x_mt}  

    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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-hoursAgoEnd_N "Returns the date and time for the end of the hour a specified number of hours ago.").

## GlideSystem - hoursAgoStart(Number hours) {#ariaid-title75}

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.
{#r_GS-hoursAgoStart_N__table_wwb_xbx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| hours | Number | Number of hours ago. |
[Table 147. Parameters]

{#r_GS-hoursAgoStart_N__table_wwb_xbx_mt} {#r_GS-hoursAgoStart_N__table_xwb_xbx_mt__entry__2}

| Type | Description |
|-|-|
| String | UTC date and time for the end of the specified number of hours ago. Format: yyyy-mm-dd hh:mm:ss |
[Table 148. Returns]

{#r_GS-hoursAgoStart_N__table_xwb_xbx_mt}  

    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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-hoursAgoStart_N "Returns the date and time for the start of the hour a specified number of hours ago.").

## GlideSystem - isFirstDayOfMonth(Object date) {#ariaid-title76}

Checks whether the date in the specified date object is the first day of the
month.
{#r_GS-isFirstDayOfMonth_O__table_pyc_x3x_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| date | Object | Date object on which to check the date, such as GlideDateTime or GlideDate. |
[Table 149. Parameters]

{#r_GS-isFirstDayOfMonth_O__table_pyc_x3x_mt} {#r_GS-isFirstDayOfMonth_O__table_qyc_x3x_mt__entry__2}

| 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. {#r_GS-isFirstDayOfMonth_O__ul_twc_kpj_z4b} |
[Table 150. Returns]

{#r_GS-isFirstDayOfMonth_O__table_qyc_x3x_mt}  
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) {#ariaid-title77}

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.
{#r_GS-isFirstDayOfWeek_O__table_dw2_hjx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| date | Object | Date object on which to check the date, such as GlideDateTime or GlideDate. |
[Table 151. Parameters]

{#r_GS-isFirstDayOfWeek_O__table_dw2_hjx_mt} {#r_GS-isFirstDayOfWeek_O__table_ew2_hjx_mt__entry__2}

| 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. |
[Table 152. Returns]

{#r_GS-isFirstDayOfWeek_O__table_ew2_hjx_mt}  
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) {#ariaid-title78}

Checks whether the date in the specified date object is the first day of the
year.
{#r_GS-isFirstDayOfYear_O__table_urv_sjx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| date | Object | Date object on which to check the date, such as GlideDateTime or GlideDate. |
[Table 153. Parameters]

{#r_GS-isFirstDayOfYear_O__table_urv_sjx_mt} {#r_GS-isFirstDayOfYear_O__table_vrv_sjx_mt__entry__2}

| 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. {#r_GS-isFirstDayOfYear_O__ul_twc_kpj_z4b} |
[Table 154. Returns]

{#r_GS-isFirstDayOfYear_O__table_vrv_sjx_mt}  
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() {#ariaid-title79}

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.
{#r_GS-isInteractive__table_bc5_kpb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 155. Parameters]

{#r_GS-isInteractive__table_bc5_kpb_mt} {#r_GS-isInteractive__table_cc5_kpb_mt__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the session is interactive. Possible values: * true: Session is interactive. * false: Session is not interactive. {#r_GS-isInteractive__ul_twc_kpj_z4b} |
[Table 156. Returns]

{#r_GS-isInteractive__table_cc5_kpb_mt}  

    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 {#r_GS-isInteractive__section_kv3_zrs_mcb}

To use the isInteractive() method in a scoped application, use the
corresponding scoped method: [isInteractive()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemIsInteractive "Checks if the current session is interactive. An example of an interactive session is when a user logs in normally. An example of a non-interactive session is using a SOAP request to retrieve data.").

## GlideSystem - isLastDayofMonth(Object date) {#ariaid-title80}

Checks whether the date in the specified date object is the last day of the
month.
{#r_GS-isLastDayofMonth_O__table_g2y_ckx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| date | Object | Date object on which to check the date, such as GlideDateTime or GlideDate. |
[Table 157. Parameters]

{#r_GS-isLastDayofMonth_O__table_g2y_ckx_mt} {#r_GS-isLastDayofMonth_O__table_h2y_ckx_mt__entry__2}

| 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. {#r_GS-isLastDayofMonth_O__ul_twc_kpj_z4b} |
[Table 158. Returns]

{#r_GS-isLastDayofMonth_O__table_h2y_ckx_mt}  
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) {#ariaid-title81}

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.
{#r_GS-isLastDayOfWeek_O__table_d55_nkx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| date | Object | Date object on which to check the date, such as GlideDateTime or GlideDate. |
[Table 159. Parameters]

{#r_GS-isLastDayOfWeek_O__table_d55_nkx_mt} {#r_GS-isLastDayOfWeek_O__table_e55_nkx_mt__entry__2}

| 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. {#r_GS-isLastDayOfWeek_O__ul_asy_2gv_1pb} |
[Table 160. Returns]

{#r_GS-isLastDayOfWeek_O__table_e55_nkx_mt}  
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) {#ariaid-title82}

Checks whether the date in the specified date object is the last day of the
year.
{#r_GS-isLastDayOfYear_O__table_c2t_xkx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| date | Object | Date object on which to check the date, such as GlideDateTime or GlideDate. |
[Table 161. Parameters]

{#r_GS-isLastDayOfYear_O__table_c2t_xkx_mt} {#r_GS-isLastDayOfYear_O__table_d2t_xkx_mt__entry__2}

| 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. {#r_GS-isLastDayOfYear_O__ul_asy_2gv_1pb} |
[Table 162. Returns]

{#r_GS-isLastDayOfYear_O__table_d2t_xkx_mt}  
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() {#ariaid-title83}

Determines if the current user is currently logged in.
{#r_GS-isLoggedIn__table_jdh_5pb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 163. Parameters]

{#r_GS-isLoggedIn__table_jdh_5pb_mt} {#r_GS-isLoggedIn__table_kdh_5pb_mt__entry__2}

| 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. {#r_GS-isLoggedIn__ul_twc_kpj_z4b} |
[Table 164. Returns]

{#r_GS-isLoggedIn__table_kdh_5pb_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemIsLoggedIn "Determines if the current user is currently logged in.").

## GlideSystem - isMobile() {#ariaid-title84}

Determines whether the request came from a mobile device.
You can use this method in UI action conditions and business rules.
{#r_GS-isMobile__table_gnw_lbz_bv__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 165. Parameters]

{#r_GS-isMobile__table_gnw_lbz_bv} {#r_GS-isMobile__table_hnw_lbz_bv__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the request came from a mobile device. Possible values: * true: Mobile device. * false: Non-mobile device. {#r_GS-isMobile__ul_twc_kpj_z4b} |
[Table 166. Returns]

{#r_GS-isMobile__table_hnw_lbz_bv}  
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 {#r_GS-isMobile__section_nwn_css_mcb}

To use the isMobile() method in a scoped application, use the
corresponding scoped method: [isMobile()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGS-isMobile "You can determine if a request comes from a mobile device.").

## GlideSystem - lastWeek() {#ariaid-title85}

Returns the date and time one week ago in GMT.
{#r_GS-lastWeek__table_tsk_mcx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 167. Parameters]

{#r_GS-lastWeek__table_tsk_mcx_mt} {#r_GS-lastWeek__table_usk_mcx_mt__entry__2}

| Type | Description |
|-|-|
| String | Date and time one week ago. Format: yyyy-MM-dd hh:mm:ss |
[Table 168. Returns]

{#r_GS-lastWeek__table_usk_mcx_mt}  
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) {#ariaid-title86}

Logs a message to the system log and saves it to the syslog table.
{#r_GS-log_S_S__table_opd_251_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| message | String | Message to log. |
| source | String | Optional. Source of the message. |
[Table 169. Parameters]

{#r_GS-log_S_S__table_opd_251_mt} {#r_GS-log_S_S__table_ppd_251_mt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 170. Returns]

{#r_GS-log_S_S__table_ppd_251_mt}  
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) {#ariaid-title87}

Logs an error to the system log and saves it to the syslog table.
{#r_GS-logError_S_S__table_ipq_q51_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| message | String | Error message to log. |
| source | String | Optional. Source of the message. |
[Table 171. Parameters]

{#r_GS-logError_S_S__table_ipq_q51_mt} {#r_GS-logError_S_S__table_jpq_q51_mt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 172. Returns]

{#r_GS-logError_S_S__table_jpq_q51_mt}  
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) {#ariaid-title88}

Logs a warning to the system log and saves it to the syslog table.
{#r_GS-logWarning_S_S__table_rvs_z51_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| message | String | Message to log. |
| source | String | Optional. Source of the message. |
[Table 173. Parameters]

{#r_GS-logWarning_S_S__table_rvs_z51_mt} {#r_GS-logWarning_S_S__table_svs_z51_mt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 174. Returns]

{#r_GS-logWarning_S_S__table_svs_z51_mt}  
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) {#ariaid-title89}

Returns a date and time for the specified number of minutes ago.
{#r_GS-minutesAgo_N__table_gnh_vcx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| minutes | Number | Number of minutes in the past to return. |
[Table 175. Parameters]

{#r_GS-minutesAgo_N__table_gnh_vcx_mt} {#r_GS-minutesAgo_N__table_hnh_vcx_mt__entry__2}

| Type | Description |
|-|-|
| String | UTC date and time for the specified number of minutes ago. Format: yyyy-mm-dd hh:mm:ss |
[Table 176. Returns]

{#r_GS-minutesAgo_N__table_hnh_vcx_mt}  
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) {#ariaid-title90}

Returns a date and time for the end of the minute a certain number of minutes
ago.
{#r_GS-minutesAgoEnd_N__table_fp2_hdx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| minutes | Number | Integer number of minutes ago, such as 5 or 11. |
[Table 177. Parameters]

{#r_GS-minutesAgoEnd_N__table_fp2_hdx_mt} {#r_GS-minutesAgoEnd_N__table_gp2_hdx_mt__entry__2}

| 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 |
[Table 178. Returns]

{#r_GS-minutesAgoEnd_N__table_gp2_hdx_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-minutesAgoEnd_N "Returns the date and time for the end of the minute a specified number of minutes ago.").

## GlideSystem - minutesAgoStart(Number minutes) {#ariaid-title91}

Returns a date and time for the start of the minute a certain number of minutes
ago.
{#r_GS-minutesAgoStart_N__table_xzm_tdx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| minutes | Number | Integer number of minutes ago, such as 15 or 112. |
[Table 179. Parameters]

{#r_GS-minutesAgoStart_N__table_xzm_tdx_mt} {#r_GS-minutesAgoStart_N__table_yzm_tdx_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT the specified number of minutes ago, at the start of the minute. Format: yyyy-mm-dd hh:mm:ss |
[Table 180. Returns]

{#r_GS-minutesAgoStart_N__table_yzm_tdx_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-minutesAgoStart_N "Returns the date and time for the start of the minute a specified number of minutes ago.").

## GlideSystem - monthsAgo(Number months) {#ariaid-title92}

Returns a date and time for a certain number of months ago.
{#r_GS-monthsAgo_N__table_phw_f2x_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| months | Number | Integer number of months ago. |
[Table 181. Parameters]

{#r_GS-monthsAgo_N__table_phw_f2x_mt} {#r_GS-monthsAgo_N__table_qhw_f2x_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT of the specified number of months ago at the exact same time. Format: yyyy-mm-dd hh:mm:ss |
[Table 182. Returns]

{#r_GS-monthsAgo_N__table_qhw_f2x_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-monthsAgo_N "Returns the date and time for a specified number of months ago.").

## GlideSystem - monthsAgoEnd(Number months) {#ariaid-title93}

Returns a date and time for the last day of the month a certain number of months
ago.
{#r_GS-monthsAgoEnd_N__table_nqx_r2x_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| months | Number | Integer number of months, such as 4 or 16. |
[Table 183. Parameters]

{#r_GS-monthsAgoEnd_N__table_nqx_r2x_mt} {#r_GS-monthsAgoEnd_N__table_oqx_r2x_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT end of the month the specified number of months ago. Format: yyyy-mm-dd hh:mm:ss |
[Table 184. Returns]

{#r_GS-monthsAgoEnd_N__table_oqx_r2x_mt}  
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) {#ariaid-title94}

Returns a date and time for the start of the month a certain number of months
ago.
{#r_GS-monthsAgoStart_N__table_xmk_bfx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| months | Number | Integer number of months ago, such as 5 or 14. |
[Table 185. Parameters]

{#r_GS-monthsAgoStart_N__table_xmk_bfx_mt} {#r_GS-monthsAgoStart_N__table_ymk_bfx_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT start of the month the specified number of months ago. Format: yyyy-mm-dd hh:mm:ss |
[Table 186. Returns]

{#r_GS-monthsAgoStart_N__table_ymk_bfx_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-monthsAgoStart_N "Returns the date and time for the start of the month a specified number of months ago.").

## GlideSystem - nil(Object obj) {#ariaid-title95}

Queries an object and returns true if the object is null or contains an empty
string.
{#r_GS-nil_O__table_pwv_jv1_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| obj | Object | The object to be checked. |
[Table 187. Parameters]

{#r_GS-nil_O__table_pwv_jv1_mt} {#r_GS-nil_O__table_qwv_jv1_mt__entry__2}

| Type | Description |
|-|-|
| Boolean | True if null or empty string; otherwise, false. |
[Table 188. Returns]

{#r_GS-nil_O__table_qwv_jv1_mt}  

    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 {#r_GS-nil_O__section_jzv_jss_mcb}

To use the nil() method in a scoped application, use the corresponding
scoped method: [nil()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemNil_Object "Queries an object and returns true if the object is null, undefined, or contains an empty string.").

## GlideSystem - now() {#ariaid-title96}

Returns the current date in UTC.
{#r_GS-now__table_w2g_nfx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 189. Parameters]

{#r_GS-now__table_w2g_nfx_mt} {#r_GS-now__table_x2g_nfx_mt__entry__2}

| Type | Description |
|-|-|
| String | The current date in the user-defined format, in UTC. |
[Table 190. Returns]

{#r_GS-now__table_x2g_nfx_mt}  

    // 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() {#ariaid-title97}

Returns the current date and time in UTC format.
{#r_GS-nowNoTZ__table_j25_yfx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 191. Parameters]

{#r_GS-nowNoTZ__table_j25_yfx_mt} {#r_GS-nowNoTZ__table_k25_yfx_mt__entry__2}

| Type | Description |
|-|-|
| String | The current UTC date time |
[Table 192. Returns]

{#r_GS-nowNoTZ__table_k25_yfx_mt}  

    // 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() {#ariaid-title98}

Returns the current date and time in the user-defined format.
{#r_GS-nowDateTime__table_wwm_jgx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 193. Parameters]

{#r_GS-nowDateTime__table_wwm_jgx_mt} {#r_GS-nowDateTime__table_xwm_jgx_mt__entry__2}

| 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](https://www.servicenow.com/docs/access?context=r_UseDateAndTimeFields&version=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US). |
[Table 194. Returns]

{#r_GS-nowDateTime__table_xwm_jgx_mt}  

    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() {#ariaid-title99}

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.
{#r_GS-nowGlideDateTime__table_v4b_nyv_v1b__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 195. Parameters]

{#r_GS-nowGlideDateTime__table_v4b_nyv_v1b} {#r_GS-nowGlideDateTime__table_w4b_nyv_v1b__entry__2}

| Type | Description |
|-|-|
| Object | GlideDateTime object with the current date and time in GMT format. |
[Table 196. Returns]

{#r_GS-nowGlideDateTime__table_w4b_nyv_v1b}  
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) {#ariaid-title100}

Writes a message to the system log.
This method does not write the message to the syslog table unless debug has been
activated.
{#r_GS-print_S__table_mkj_yv1_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| message | String | The message to log |
[Table 197. Parameters]

{#r_GS-print_S__table_mkj_yv1_mt} {#r_GS-print_S__table_nkj_yv1_mt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 198. Returns]

{#r_GS-print_S__table_nkj_yv1_mt}  

    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) {#ariaid-title101}

Returns a date and time for a certain number of quarters ago.
{#r_GS-quartersAgo_N__table_i12_zgx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| quarters | Number | Integer number of the quarters ago. |
[Table 199. Parameters]

{#r_GS-quartersAgo_N__table_i12_zgx_mt} {#r_GS-quartersAgo_N__table_j12_zgx_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT of the quarter that was the specified number of quarters ago. Format: yyyy-mm-dd hh:mm:ss |
[Table 200. Returns]

{#r_GS-quartersAgo_N__table_j12_zgx_mt}  
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) {#ariaid-title102}

Returns a date and time for the last day of the quarter, for a specified number of
quarters ago.
{#r_GS-quartersAgoEnd_N__table_kbb_lhx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| quarters | Number | An integer number of quarters |
[Table 201. Parameters]

{#r_GS-quartersAgoEnd_N__table_kbb_lhx_mt} {#r_GS-quartersAgoEnd_N__table_lbb_lhx_mt__entry__2}

| 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 |
[Table 202. Returns]

{#r_GS-quartersAgoEnd_N__table_lbb_lhx_mt}

### Scoped equivalent

To use the quartersAgoEnd() method in a scoped application, use the
corresponding scoped method: [quartersAgoEnd()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-quartersAgoEnd_N "Returns the date and time for the last day of the quarter for a specified number of quarters ago.").

## GlideSystem - quartersAgoStart(Number quarters) {#ariaid-title103}

Returns a date and time for the first day of the quarter, for a specified number of
quarters ago.
{#r_GS-quartersAgoStart_N__table_cmq_5hx_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| quarters | Number | An integer number of quarters |
[Table 203. Parameters]

{#r_GS-quartersAgoStart_N__table_cmq_5hx_mt} {#r_GS-quartersAgoStart_N__table_dmq_5hx_mt__entry__2}

| 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 |
[Table 204. Returns]

{#r_GS-quartersAgoStart_N__table_dmq_5hx_mt}

### Scoped equivalent

To use the quartersAgoStart() method in a scoped application, use the
corresponding scoped method: [quartersAgoStart()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-quartersAgoStart_N "Returns the date and time for the first day of the quarter for a specified number of quarters ago.").

## GlideSystem - setProperty(String key, String value, String description) {#ariaid-title104}

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.
{#r_GS-setProperty_S_S_S__table_cbs_vqx_fw__entry__3}

| 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 205. Parameters]

{#r_GS-setProperty_S_S_S__table_cbs_vqx_fw} {#r_GS-setProperty_S_S_S__table_dbs_vqx_fw__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 206. Returns]

{#r_GS-setProperty_S_S_S__table_dbs_vqx_fw}  

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

Output: bar

### Scoped equivalent {#r_GS-setProperty_S_S_S__section_rsz_rss_mcb}

To use the setProperty() method in a scoped application, use the
corresponding scoped method: [setProperty()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_SGSYS-setProperty_S_S_S "Sets the specified key to the specified value if the property is within the script's scope.").

## GlideSystem - setRedirect(Object URI) {#ariaid-title105}

Sets the redirect URI for this transaction, which then determines the next page the
user will see.
{#r_GS-setRedirect_O__table_x4z_cqb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| URI | Object | URI to set as the redirect |
[Table 207. Parameters]

{#r_GS-setRedirect_O__table_x4z_cqb_mt} {#r_GS-setRedirect_O__table_y4z_cqb_mt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 208. Returns]

{#r_GS-setRedirect_O__table_y4z_cqb_mt}  
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 {#r_GS-setRedirect_O__section_bjq_tss_mcb}

To use the setRedirect() method in a scoped application, use the
corresponding scoped method: [setRedirect()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemSetRedirect_Object "Sets the redirect URI for this transaction, which then determines the next page the user will see.").

## GlideSystem - setReturn(Object URI) {#ariaid-title106}

Sets the return URI for this transaction. This determines what page the user will be
directed to when they return from the next form.
{#r_GS-setReturn_O__table_if4_rqb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| URI | Object | URI to set as the return location. |
[Table 209. Parameters]

{#r_GS-setReturn_O__table_if4_rqb_mt} {#r_GS-setReturn_O__table_jf4_rqb_mt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 210. Returns]

{#r_GS-setReturn_O__table_jf4_rqb_mt}  
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) {#ariaid-title107}

Determines if a database table exists in the ServiceNow
instance.
{#r_GS-tableExists_S__table_e3j_gw1_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | Name of the table to check. |
[Table 211. Parameters]

{#r_GS-tableExists_S__table_e3j_gw1_mt} {#r_GS-tableExists_S__table_f3j_gw1_mt__entry__2}

| 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 {#r_GS-tableExists_S__ul_fp4_xp4_krb} |
[Table 212. Returns]

{#r_GS-tableExists_S__table_f3j_gw1_mt}  
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()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemTableExists_String "Determines if a database table exists.").

## GlideSystem - userID() {#ariaid-title108}

Returns the sys_id of the user associated with this session. Use
getUserID() instead.
{#r_GS-userID__table_wh2_drb_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 213. Parameters]

{#r_GS-userID__table_wh2_drb_mt} {#r_GS-userID__table_xh2_drb_mt__entry__2}

| Type | Description |
|-|-|
| String | Sys_id of the current user. |
[Table 214. Returns]

{#r_GS-userID__table_xh2_drb_mt}  
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) {#ariaid-title109}

Deletes any open scheduled job records in the Schedule (sys_trigger) table for the
specified GlideRecord.
{#r_GS-workflowFlush_O__table_p5r_rw1_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| glideRecord | Object | The GlideRecord |
[Table 215. Parameters]

{#r_GS-workflowFlush_O__table_p5r_rw1_mt} {#r_GS-workflowFlush_O__table_q5r_rw1_mt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 216. Returns]

{#r_GS-workflowFlush_O__table_q5r_rw1_mt}

## GlideSystem - yearsAgo(Number years) {#ariaid-title110}

Gets a date and time for a certain number of years ago.
{#r_GS-yearsAgo_N__table_o2l_23x_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| years | Number | An integer number of years |
[Table 217. Parameters]

{#r_GS-yearsAgo_N__table_o2l_23x_mt} {#r_GS-yearsAgo_N__table_p2l_23x_mt__entry__2}

| 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. |
[Table 218. Returns]

{#r_GS-yearsAgo_N__table_p2l_23x_mt}

### Scoped equivalent

To use the yearsAgo(Number years) method in a scoped application, use
the corresponding scoped method: [yearsAgo(Number years)](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#r_ScopedGlideSystemYearsAgo_N "Returns a date and time for a certain number of years ago.").

## GlideSystem - yesterday() {#ariaid-title111}

Returns yesterday's time (24 hours ago).
{#r_GS-yesterday__table_y4t_p3x_mt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 219. Parameters]

{#r_GS-yesterday__table_y4t_p3x_mt} {#r_GS-yesterday__table_z4t_p3x_mt__entry__2}

| Type | Description |
|-|-|
| String | GMT for 24 hours ago, in the format yyyy-mm-dd hh:mm:ss |
[Table 220. Returns]

{#r_GS-yesterday__table_z4t_p3x_mt}

### Scoped equivalent

To use the yesterday() method in a scoped application, use the
corresponding scoped method: [yesterday()](https://servicenow-prod.fluidtopics.net/3Hp1FQjMKidd9ATK9vFJrA#SGSYS-yesterday "Returns yesterday's time (24 hours ago).").

