{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1036,"path":"api-reference/server-api-reference/c_GlideSystemAPI.md","title":"GlideSystem - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideSystem- Global\n\nThe 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.\n\nMany of the GlideSystem methods facilitate the easy inclusion of dates in query ranges, and are most often used in filters and reporting.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## GlideSystem - addErrorMessage\\(Object message\\)\n\nAdds an error message for the current session.\n\nUse getErrorMessages\\(\\) to retrieve a list of error messages currently being shown.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|Object|The message to add.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\ngs.include(\"PrototypeServer\");\n  var ValidatePasswordStronger = Class.create();\n  ValidatePasswordStronger.prototype = {\n       process : function() {\n          var user_password = request.getParameter(\"user_password\");\n          var min_len = 8;\n          var rules = \"Password must be at least \" + min_len + \n             \" characters long and contain a digit, an uppercase letter, and a lowercase letter.\";\n          if (user_password.length() < min_len) {\n             gs.addErrorMessage(\"TOO SHORT: \" + rules);\n             return false;\n          }\n          var digit_pattern = new RegExp(\"[0-9]\", \"g\");\n          if (!digit_pattern.test(user_password)) {\n             gs.addErrorMessage(\"DIGIT MISSING: \" + rules);\n             return false;\n          }\n          var upper_pattern = new RegExp(\"[A-Z]\", \"g\");\n          if (!upper_pattern.test(user_password)) {\n             gs.addErrorMessage(\"UPPERCASE MISSING: \" + rules);\n             return false;\n          }\n          var lower_pattern = new RegExp(\"[a-z]\", \"g\");\n          if (!lower_pattern.test(user_password)) {\n             gs.addErrorMessage(\"LOWERCASE MISSING: \" + rules);\n             return false;\n          }\n          return true; // password is OK\n       }\n  }\n[edit]\n```\n\n### Scoped equivalent\n\nTo use the addErrorMessage\\(\\) method in a scoped application, use the corresponding scoped method: [addErrorMessage\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - addHighMessage\\(String message\\)\n\nDisplays a high priority message at the top of the form.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|High priority message to display.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how to display a high priority message at the top of the form.\n\n```\ngs.addHighMessage(\"This is a high priority message\");\n```\n\n## GlideSystem - addInfoMessage\\(Object message\\)\n\nAdds an info message for the current session.\n\nUse 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|Object|The message to add.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nif ((!current.u_date1.nil()) && (!current.u_date2.nil())) {\n  var start = current.u_date1.getGlideObject().getNumericValue();\n  var end = current.u_date2.getGlideObject().getNumericValue();\n  if (start > end) {\n    gs.addInfoMessage('start must be before end');\n    current.u_date1.setError('start must be before end');\n    current.setAbortAction(true);\n  }\n}\n```\n\n### Scoped equivalent\n\nTo use the addInfoMessage\\(\\) method in a scoped application, use the corresponding scoped method: [addInfoMessage\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - addLowMessage\\(String message\\)\n\nDisplays a low priority message at the top of the form.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|Low priority message to display.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how to display a low priority message at the top of the form.\n\n```\ngs.addLowMessage(\"This is a low priority message\");\n```\n\n## GlideSystem - addMessage\\(String type, Object message\\)\n\nAdds a message for the current session.\n\n|Name|Type|Description|\n|----|----|-----------|\n|type|String|Type of message, such as `error` or `info`.|\n|message|Object|Message to add to the current session.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n## GlideSystem - addModerateMessage\\(String message\\)\n\nDisplays a moderate priority message at the top of the form.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|Moderate message to display.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows how to display a moderate priority message at the top of the form.\n\n```\ngs.addModerateMessage(\"This is a moderate priority message\");\n```\n\n## GlideSystem - addSuccessMessage\\(String message\\)\n\nDisplays a message confirming a successful action at the top of the form.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|Success message to display.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how to display a message confirming a success message at the top of the form.\n\n```\ngs.addSuccessMessage(\"This is a success message\");\n```\n\n## GlideSystem - beginningOfLastMonth\\(\\)\n\nGets the date and time for the beginning of last month in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The UTC beginning of last month, in the format yyyy-mm-dd hh:mm:ss.|\n\nThis example sets the date and time of the GlideDateTime object to the beginning of last month.\n\n```\nvar date = new GlideDate();\ndate.setValue(gs.beginningOfLastMonth());\nvar dateasint = date.toString().replace('-','');\ngs.print(dateasint);\n```\n\n### Scoped equivalent\n\nTo use the beginningOfLastMonth\\(\\) method in a scoped application, use the corresponding scoped method: [beginningOfLastMonth\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - beginningOfLastWeek\\(\\)\n\nReturns the date and time for the beginning of last week in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_ogp_m5v_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC beginning of last week. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example sets the value of the current Glide date/time record to the beginning of last week.\n\n```\nvar gdt2 = new GlideDateTime(dt);\ngdt2.setValue(gs.beginningOfLastWeek());\n```\n\n### Scoped equivalent\n\nTo use the beginningOfLastWeek\\(\\) method in a scoped application, use the corresponding scoped method: [beginningOfLastWeek\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - beginningOfNextWeek\\(\\)\n\nReturns the date and time for the beginning of next week in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_i2f_v5v_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC beginning of next week. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example sets the value of the current Glide date/time record to the beginning of next week.\n\n```\nvar gdt2 = new GlideDateTime(dt);\ngdt2.setValue(gs.beginningOfNextWeek());\n```\n\n### Scoped equivalent\n\nTo use the beginningOfNextWeek\\(\\) method in a scoped application, use the corresponding scoped method: [beginningOfNextWeek\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - beginningOfNextMonth\\(\\)\n\nReturns the date and time for the beginning of next month in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_qp1_dvv_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC beginning of next month. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example sets the value of the current Glide date/time record to the beginning of next month.\n\n```\nvar gdt2 = new GlideDateTime(dt);\ngdt2.setValue(gs.beginningOfNextMonth());\n```\n\n### Scoped equivalent\n\nTo use the beginningOfNextMonth\\(\\) method in a scoped application, use the corresponding scoped method: [beginningOfNextMonth\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - beginningOfNextYear\\(\\)\n\nReturns the date and time for the beginning of next year in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The UTC beginning of next year, in the format yyyy-mm-dd hh:mm:ss.|\n\nThis example sets the value of the current Glide date/time record to the beginning of next year.\n\n```\nvar gdt2 = new GlideDateTime(dt);\ngdt2.setValue(gs.beginningOfNextYear());\n```\n\n### Scoped equivalent\n\nTo use the beginningOfNextYear\\(\\) method in a scoped application, use the corresponding scoped method: [beginningOfNextYear\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - beginningOfThisMonth\\(\\)\n\nReturns the date and time for the beginning of the current month in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_nkk_tvv_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC beginning of the current month. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example sets the value of the current Glide date/time record to the beginning of this month.\n\n```\nvar gdt2 = new GlideDateTime(dt);\ngdt2.setValue(gs.beginningOfThisMonth());\n```\n\n### Scoped equivalent\n\nTo use the beginningOfThisMonth\\(\\) method in a scoped application, use the corresponding scoped method: [beginningOfThisMonth\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - beginningOfThisQuarter\\(\\)\n\nReturns the date and time for the beginning of the current quarter in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_us5_1wv_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC beginning of the current quarter. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example sets the value of the current Glide date/time record to the beginning of the current quarter.\n\n```\nvar gdt2 = new GlideDateTime(dt);\ngdt2.setValue(gs.beginningOfThisQuarter());\n```\n\n### Scoped equivalent\n\nTo use the beginningOfThisQuarter\\(\\) method in a scoped application, use the corresponding scoped method: [beginningOfThisQuarter\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - beginningOfThisWeek\\(\\)\n\nReturns the date and time for the beginning of this week in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_bmj_3wv_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC beginning of the current week. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example sets the value of the current Glide date/time record to the beginning of the current week.\n\n```\nvar gdt2 = new GlideDateTime(dt);\ngdt2.setValue(gs.beginningOfThisWeek());\n```\n\n### Scoped equivalent\n\nTo use the beginningOfThisWeek\\(\\) method in a scoped application, use the corresponding scoped method: [beginningOfThisWeek\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - beginningOfThisYear\\(\\)\n\nReturns the date and time for the beginning of this year in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_psd_5wv_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC beginning of the current year. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example sets the value of the current Glide date/time record to the beginning of the current year.\n\n```\nvar gdt2 = new GlideDateTime(dt);\ngdt2.setValue(gs.beginningOfThisYear());\n```\n\n### Scoped equivalent\n\nTo use the beginningOfThisYear\\(\\) method in a scoped application, use the corresponding scoped method: [beginningOfThisYear\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - beginningOfToday\\(\\)\n\nRetrieves the date and time for the beginning of today in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_wgl_bxv_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC beginning of the current day. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example sets the value of the current Glide date/time record to the beginning of the current day.\n\n```\nvar gdt2 = new GlideDateTime(dt);\ngdt2.setValue(gs.beginningOfToday());\n```\n\n## GlideSystem - beginningOfTomorrow\\(\\)\n\nRetrieves the \\(UTC\\) beginning of tomorrow adjusted for the timezone of the user's current session.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_wgl_bxv_dm\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC beginning of tomorrow. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>```\nvar today = new GlideDateTime(gs.beginningOfTomorrow()).getNumericValue();\n```\n\n## GlideSystem - beginningOfYesterday\\(\\)\n\nRetrieves the date and time for the beginning of yesterday in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The UTC beginning of yesterday, in the format yyyy-mm-dd hh:mm:ss.|\n\n```\nvar start = new GlideDateTime();\nstart.setValue(gs.beginningOfYesterday());\n```\n\n## GlideSystem - calDateDiff\\(String startDate, String endDate, Boolean numericValue\\)\n\nCalculate the difference between two dates using the default calendar.\n\nCalendars are now legacy. If Schedules are being used, see the 'Calculate during a given schedule' section of the topic [Scheduling script use cases](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/c_UsefulSchedulingScripts.md).\n\n<table id=\"table_ulx_gyv_mt\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nstartDate\n\n</td><td>\n\nString\n\n</td><td>\n\nStarting date to compare in the current user's date format.\n\n</td></tr><tr><td>\n\nendDate\n\n</td><td>\n\nString\n\n</td><td>\n\nEnding date to compare in the current user's date format.\n\n</td></tr><tr><td>\n\nnumericValue\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates ther format of the returned time value.Valid values:\n\n -   true: Return value is formatted in number of seconds\n-   false: Return value is formatted ddd hh:mm:ss.\n\n</td></tr></tbody>\n</table><table id=\"table_vlx_gyv_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nIf 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.\n\n</td></tr></tbody>\n</table>```\nvar endDateTime = gs.nowDateTime();\ngs.print('--- Total records: ' + countRecordsTotal);\ngs.print('--- End time: ' + endDateTime);\ngs.print('Time diff: ' + gs.calDateDiff(startDateTime, endDateTime));\n```\n\n## GlideSystem - dateDiff\\(String startDate, String endDate, Boolean numericValue\\)\n\nCalculates the difference between two dates.\n\nThis 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.\n\nThis 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.\n\nIf you are working with GlideDateTime objects use the GlideDateTime subtract\\(\\) method instead of dateDiff\\(\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|startDate|String|The starting date to compare in the current user's date format.|\n|endDate|String|The ending date to compare in the current user's date format.|\n|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.|\n\n|Type|Description|\n|----|-----------|\n|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.|\n\n```\n// Given two date/times as DateTime objects\n// Set the values this way to ensure a consistent input time\nvar date1 = new GlideDateTime();\nvar date2 = new GlideDateTime();\ndate1.setDisplayValueInternal('2014-01-01 12:00:00');\ndate2.setDisplayValueInternal('2014-01-01 13:00:00');\n \n// Determine the difference as number of seconds (returns a string)\n// Use getDisplayValue() to convert the string to the format expected by dateDiff()\nvar diffSeconds = gs.dateDiff(date1.getDisplayValue(), date2.getDisplayValue(), true);\n \n// JavaScript will coerce diffSeconds from a string to a number\n// since diffSeconds is being compared to a number\nvar msg = (diffSeconds <= 0) ? ' is on or after ' : ' is before ';\ngs.print(date1.getDisplayValue() + msg + date2.getDisplayValue())\n```\n\n## GlideSystem - dateGenerate\\(String date, String range\\)\n\nGenerates a date and time for the specified date in the user's session time zone as a UTC timestamp.\n\n<table id=\"table_ghf_3jw_mt\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ndate\n\n</td><td>\n\nString\n\n</td><td>\n\nDate to generate in UTC.Format: yyyy-mm-dd\n\n</td></tr><tr><td>\n\nrange\n\n</td><td>\n\nString\n\n</td><td>\n\nStart, end, or a time. Format: 24-hour hh:mm:ss\n\n</td></tr></tbody>\n</table><table id=\"table_hhf_3jw_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nGenerated date and time. If the range is `start`, the returned value is yyyy-mm-dd 00:00:00.\n\nIf range is `end` the return value is yyyy-mm-dd 23:59:59.\n\nFormat: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example shows using dateGenerate\\(\\) to set the start date when querying records in the Incident table.\n\n```\nvar tableData = new GlideRecord('incident');\ntableData.addEncodedQuery(\"sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-07','00:00:00')@javascript:gs.daysAgoEnd(0)^priority=1^severityIN1,2\");\ntableData.query();\ngs.info(\"Count: \" + tableData.getRowCount());\n```\n\nOutput:\n\n```\nCount: 7\n```\n\n### Scoped equivalent\n\nTo use the dateGenerate\\(\\) method in a scoped application, use the corresponding scoped method: [dateGenerate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - daysAgo\\(Number days\\)\n\nReturns a date and time for a certain number of days ago. Returned in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|days|Number|Number of days|\n\n<table id=\"table_wlc_zjw_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC of the specified number of days ago. Format: yyyy-mm-dd hh:mm:ss.\n\n</td></tr></tbody>\n</table>```\nfunction contractNoticeDue() {\n  var now_GR = new GlideRecord(\"contract\");\n  now_GR.addQuery(\"u_contract_status\", \"Active\");\n  now_GR.query();\n  while (now_GR.next()) {\n    if ((now_GR.u_termination_date <= gs.daysAgo(-90)) && (now_GR.u_contract_duration == \"Long\")) {\n      now_GR.u_contract_status = \"In review\";\n    } \n    else if ((now_GR.u_termination_date <= gs.daysAgo(-50)) && (now_GR.u_contract_duration == \"Medium\")) {\n      now-GR.u_contract_status = \"In review\";\n    }\n    else if ((now_GR.u_termination_date <= gs.daysAgo(-10)) && (now_GR.u_contract_duration == \"Short\")) {\n      now_GR.u_contract_status = \"In review\";\n    }\n  }\n  now_GR.update();\n}\n```\n\n### Scoped equivalent\n\nTo use the daysAgo\\(\\) method in a scoped application, use the corresponding scoped method: [daysAgo\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - daysAgoEnd\\(Number days\\)\n\nReturns a date and time for the end of the day a specified number of days ago. Returns the value in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|days|Number|Integer number of days|\n\n|Type|Description|\n|----|-----------|\n|String|The UTC end of the day in the format yyyy-mm-dd hh:mm:ss.|\n\nThis example shows using daysAgoEnd\\(\\) to set the end date when querying records in the Incident table.\n\n```\nvar tableData = new GlideRecord('incident');\ntableData.addEncodedQuery(\"sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-07','00:00:00')@javascript:gs.daysAgoEnd(0)^priority=1^severityIN1,2\");\ntableData.query();\ngs.addInfoMessage(\"Count: \" +tableData.getRowCount());\n```\n\n### Scoped equivalent\n\nTo use the daysAgoEnd\\(\\) method in a scoped application, use the corresponding scoped method: [daysAgoEnd\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - daysAgoLocal\\(Number days\\)\n\nReturns 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\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|days|Number|Number of days ago|\n\n|Type|Description|\n|----|-----------|\n|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.|\n\n```\nif (due_in == \"1 Day\") {\n  dd = gs.daysAgoLocal(-1);\n}\nif (due_in == \"1 Week\") {\n  dd = gs.daysAgoLocal(-7);\n}\n```\n\n## GlideSystem - daysAgoStart\\(Number days\\)\n\nReturns a date and time for the beginning of the day a specified number of days ago. Returned in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|days|String|Integer number of days|\n\n|Type|Description|\n|----|-----------|\n|String|UTC start of the day in the format yyyy-mm-dd hh:mm:ss|\n\n```\nvar now_GR = new GlideRecord('sysapproval_approver');\nnow_GR.addQuery('state', 'requested');\nnow_GR.addQuery('sys_updated_on', '<', gs.daysAgoStart(5));\nnow_GR.query();\n```\n\n### Scoped equivalent\n\nTo use the daysAgoStart\\(\\) method in a scoped application, use the corresponding scoped method: [daysAgoStart\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - endOfLastMonth\\(\\)\n\nReturns the date and time for the end of last month in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_ff1_jlw_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC of the end of last month. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example shows how to query a report record from the last day of last month.\n\n```\nvar month = gs.endOfLastMonth();\nvar monthd = new GlideDateTime(month);\nmonthd.addDays(-1);\n\nvar queueLast = new GlideRecord('u_amazon_connect_phone_metrics');\nqueueMtd.addQuery('u_queue_name',queueNames[i]);\nqueueMtd.addEncodedQuery('u_time_range=MTD');\nqueueMtd.addEncodedQuery('u_report_date'+ monthd);\nqueueMtd.orderByDesc('u_report_date');\n        \nqueueMtd.query();\n\nif(queueMtd.next()){\n  gs.info(queueMtd.u_report_date);\n} \n```\n\n### Scoped equivalent\n\nTo use the endOfLastMonth\\(\\) method in a scoped application, use the corresponding scoped method: [endOfLastMonth\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - endOfLastWeek\\(\\)\n\nReturns the date and time for the end of last week in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_nth_qlw_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC end of last week. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example shows how to query records opened on the last week of the previous month.\n\n```\nvar inc = new GlideRecord('incident');\ninc.addQuery('active=true^priority=1^opened_atONLast month@javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth()^opened_atONLast week@javascript:gs.beginningOfLastWeek()@javascript:gs.endOfLastWeek()');\ninc.query();\nwhile(inc.next())\n {\n   gs.addInfoMessage(inc.getRowCount());\n }\n```\n\n### Scoped equivalent\n\nTo use the endOfLastWeek\\(\\) method in a scoped application, use the corresponding scoped method: [endOfLastWeek\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - endOfLastYear\\(\\)\n\nReturns the date and time for the end of last year in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|UTC in format yyyy-mm-dd hh:mm:ss.|\n\nThis example shows how to query records created for all records created in the last year.\n\n```\nvar inc = new GlideRecord('incident');\ninc.addEncodedQuery('sys_created_onONLast year@javascript:gs.beginningOfLastYear()@javascript:gs.endOfLastYear()');\ninc.query();\nwhile(inc.next()){\n  inc.assignment_group = \"d625dccec0a8016700a222a0f7900d06\";\n  inc.update();\n}\n```\n\n### Scoped equivalent\n\nTo use the endOfLastYear\\(\\) method in a scoped application, use the corresponding scoped method: [endOfLastYear\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - endOfNextMonth\\(\\)\n\nReturns the date and time for the end of next month in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_dpz_xww_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC data and time. Format yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example shows how to query KB knowledge records created since the beginning of today until the end of next month.\n\n```\nvar query = \"kb_knowledge_base=e81c9a0ddbc15810c38f0763b99619c1^ORkb_knowledge_base=21302e89db055810c38f0763b99619cc^valid_toBETWEENjavascript:gs.beginningOfToday()@javascript:gs.endOfNextMonth()^ORworkflow_state=pending_retirement^latest=true\";\nvar rec = new GlideRecord('kb_knowledge');\nrec.addEncodedQuery(query);\nrec.addQuery('author', current.author);\nrec.query();\nwhile (rec.next()) {\n  var Kbtitle = rec.getValue('short_description');\n  articles.push(rec.number.toString()+ '' + Kbtitle);\n  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>');\n}\nvar articlesList = \"<ul>\";\nfor (i = 0; i <= articles.length-1; i++) {\n  articlesList = articlesList + \"<li>\" + articles[i] + \"</li>\";\n}\narticlesList = articlesList + \"</ul>\";\n```\n\n### Scoped equivalent\n\nTo use the endOfNextMonth\\(\\) method in a scoped application, use the corresponding scoped method: [endOfNextMonth\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - endOfNextWeek\\(\\)\n\nReturns the date and time for the end of next week in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_d2q_kxw_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC date and time for the end of next week.Format yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example shows how to use endOfNextWeek\\(\\) in a query to obtain all visitors in the past week.\n\n```\nvar title = 'Visitors arriving this Week';\nvar visitorQuery = 'active=true^category=visitor_request^u_my_start_dateONThis week@javascript:gs.beginningOfThisWeek()@javascript:gs.endOfNextWeek()';\n```\n\n### Scoped equivalent\n\nTo use the endOfNextWeek\\(\\) method in a scoped application, use the corresponding scoped method: [endOfNextWeek\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - endOfNextYear\\(\\)\n\nReturns the date and time for the end of next year in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_v3w_rxw_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC date and time for the end of next year.Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example shows how to use endOfNextYear\\(\\) to set the GlideDateTime object to the end of next year.\n\n```\nsetEndDate : function(dt) {\n  var gdt2 = new GlideDateTime(dt);\n  gdt2.setValue(gs.endOfNextYear());\n}\n```\n\n### Scoped equivalent\n\nTo use the endOfNextYear\\(\\) method in a scoped application, use the corresponding scoped method: [endOfNextYear\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - endOfThisMonth\\(\\)\n\nReturns the date and time for the end of this month in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_cky_lyw_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC date and time for the end of this month. Format yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example shows how to use endOfThisMonth\\(\\) to set the GlideDateTime object to the end of the current month.\n\n```\nsetEndDate : function(dt) {\n  var gdt2 = new GlideDateTime(dt);\n  gdt2.setValue(gs.endOfThisMonth());\n}\n```\n\n### Scoped equivalent\n\nTo use the endOfThisMonth\\(\\) method in a scoped application, use the corresponding scoped method: [endOfThisMonth\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - endOfThisQuarter\\(\\)\n\nReturns the date and time for the end of this quarter in the user's session time zone as a UTC timestamp..\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_jjn_5yw_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC date and time for the end of this quarter. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example shows how to use endOfThisQuarter\\(\\) to set the GlideDateTime object to the end of the current month.\n\n```\nsetEndDate : function(dt) {\n  var gdt2 = new GlideDateTime(dt);\n  gdt2.setValue(gs.endOfThisQuarter());\n}\n```\n\n### Scoped equivalent\n\nTo use the endOfThisQuarter\\(\\) method in a scoped application, use the corresponding scoped method: [endOfThisQuarter\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - endOfThisWeek\\(\\)\n\nReturns the date and time for the end of this week in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_kqb_czw_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC date and time for the end of this week. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example shows how to use endOfThisWeek\\(\\) to set the GlideDateTime object to the end of the current month.\n\n```\nsetEndDate : function(dt) {\n  var gdt2 = new GlideDateTime(dt);\n  gdt2.setValue(gs.endOfThisWeek());\n}\n```\n\n### Scoped equivalent\n\nTo use the endOfThisWeek\\(\\) method in a scoped application, use the corresponding scoped method: [endOfThisWeek\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - endOfThisYear\\(\\)\n\nReturns the date and time for the end of this year in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_byg_4zw_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC date and time for the end of this year.Format yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example shows how to use endOfThisYear\\(\\) to set the GlideDateTime object to the end of the current month.\n\n```\nsetEndDate : function(dt) {\n  var gdt2 = new GlideDateTime(dt);\n  gdt2.setValue(gs.endOfThisYear());\n}\n```\n\n### Scoped equivalent\n\nTo use the endOfThisYear\\(\\) method in a scoped application, use the corresponding scoped method: [endOfThisYear\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - endOfToday\\(\\)\n\nRetrieves the date and time for the end of today in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|UTC in the format yyyy-mm-dd hh:mm:ss.|\n\n```\nvar beginToday = gs.beginningOfToday(); \n        var endToday = gs.endOfToday(); \n        var beginTomorrow = gs.beginningOfTomorrow(); \n        var endTomorrow = gs.endOfTomorrow(); \n        var beginYesterday = gs.beginningOfYesterday(); \n        var endYesterday = gs.endOfYesterday(); \n        \n        gs.info('beginningOfToday: ' + beginToday); \n        gs.info('endOfToday: ' + endToday); \n        gs.info('-----------'); \n        gs.info('beginningOfTomorrow: ' + beginTomorrow); \n        gs.info('endOfTomorrow: ' + endTomorrow); \n        gs.info('beginningOfYesterday: ' + beginYesterday); \n        gs.info('endOfYesterday: ' + endYesterday); \n        gs.info('-----------'); \n        var gdt1 = new GlideDateTime(beginToday); \n        var gdt2 = new GlideDateTime(beginTomorrow); \n        var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2 \n        gs.info('BeginTomorrow: ' + dur.getDisplayValue()); \n        \n        var gdt1 = new GlideDateTime(endToday); \n        var gdt2 = new GlideDateTime(endTomorrow); \n        var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2 \n        gs.info('EndTomorrow: ' + dur.getDisplayValue()); \n        \n        var gdt1 = new GlideDateTime(beginToday); \n        var gdt2 = new GlideDateTime(beginYesterday); \n        var dur = GlideDateTime.subtract(gdt2, gdt1); //the difference between gdt1 and gdt2 \n        gs.info('BeginningYesterday: ' + dur.getDisplayValue()); \n        \n        var gdt1 = new GlideDateTime(endToday); \n        var gdt2 = new GlideDateTime(endYesterday); \n        var dur = GlideDateTime.subtract(gdt2, gdt1); //the difference between gdt1 and gdt2 \n        gs.info('EndYesterday: ' + dur.getDisplayValue());\n```\n\n## GlideSystem - endOfTomorrow\\(\\)\n\nRetrieves the date and time for the end of tomorrow in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|UTC in the format yyyy-mm-dd hh:mm:ss.|\n\n```\nvar tomorrowEnd = new GlideDateTime();\ntomorrowEnd.setValue(gs.endOfTomorrow());\n```\n\n## GlideSystem - endOfYesterday\\(\\)\n\nGets the date and time for the end of yesterday in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|UTC in the format \\(yyyy-mm-dd huh:mm:ss\\).|\n\n```\nvar yesterdayEnd = new GlideDateTime();\nyesterdayEnd.setValue(gs.endOfYesterday());\n```\n\n## GlideSystem - eventQueue\\(String name, Object glideRecord, String parm1, String parm2, String queue\\)\n\nQueues an event for the event manager.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Name of the event being queued.|\n|glideRecord|Object|GlideRecord object, such as \"current\".|\n|parm1|String|\\(Optional\\) Saved with the instance if specified.|\n|parm2|String|\\(Optional\\) Saved with the instance if specified.|\n|queue|String|Name of the queue.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nif (current.operation() != 'insert' && current.comments.changes()) {\n    gs.eventQueue(\"incident.commented\", current, gs.getUserID(), gs.getUserName());\n}\n```\n\n### Scoped equivalent\n\nTo use the eventQueue\\(\\) method in a scoped application, use the corresponding scoped method: [eventQueue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - eventQueueScheduled\\(String name, Object glideRecord, String parm1, String parm2, Object expiration\\)\n\nQueues an event for the event manager at a specified date and time.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Name of the event being queued.|\n|glideRecord|Object|GlideRecord object, such as \"current\".|\n|parm1|String|\\(Optional\\) Saved with the instance if specified.|\n|parm2|String|\\(Optional\\) Saved with the instance if specified.|\n|expiration|Object|Date and time to process this event.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nif (current.operation() != 'insert' && current.comments.changes()) {\n    gs.eventQueueScheduled(\"incident.commented\", current, gs.getUserID(), gs.getUserName(), new GlideDateTime('2018-06-02 20:00:00'));\n}\n```\n\n### Scoped equivalent\n\nTo use the eventQueueScheduled\\(\\) method in a scoped application, use the corresponding scoped method: [eventQueueScheduled\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - flushMessages\\(\\)\n\nClears session messages saved using addErrorMessage\\(\\) or addInfoMessage\\(\\).\n\nSession messages are shown at the top of the form. In client side scripts, use g\\_form.clearMessages\\(\\) to remove session messages.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThis example shows how to parse through and pass back error messages and then clears the messages using flushMessages\\(\\).\n\n```\nMySessionUtil.getSessionError = function() {\n  var msg = null;\n  var msgs = gs.getErrorMessages().toArray();\n  if (msgs.length > 0) {\n    msg = msgs[0] + '';\n    gs.flushMessages();\n  }\n  return msg;\n};\n\n```\n\n## GlideSystem - getAvatar\\(\\)\n\nReturns the file path to the user's avatar.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The file path to the user's avatar.|\n\n```\nvar avatarFile = gs.getUser().getAvatar();        \ngs.addInfoMessage('User avatar ID: ' + avatarFile);\n```\n\nOutput:\n\n```\nUser avatar ID: c148e1d13741310042106710ce41f149.iix?t=small\n```\n\n## GlideSystem - getCurrentScopeName\\(\\)\n\nReturns the name of the current application scope.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Current scope name.|\n\nThis example shows how to use getCurrentScopeName\\(\\) to get the scope of the processor.\n\n```\nvar incident_GR = new GlideRecord('Incident');\n\nif (incident_GR.get(\"2e3f6baddb9ad600added8fdbf9618cb\")) {\n  gs.debug(\"processor scope = \"+ gs.getCurrentScopeName());\n  var w = new global.Workflow();\n  var context = w.startFlow('1f4a4baddb9ad600affed8fdbf9619bc', incident_GR, \"update\");   //id = id workflow\n}\n```\n\n### Scoped equivalent\n\nTo use the getCurrentScopeName\\(\\) method in a scoped application, use the corresponding scoped method: [getCurrentScopeName\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - getDateFormat\\(\\)\n\nReturns the date format associated with the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The date format associated with the current user.|\n\nThe following example returns the date format associated with the user.\n\n```\nvar userDateFormat = gs. getDateFormat();\ngs.info(userDateFormat);\n\n```\n\nOutput:\n\n```\nyyyy-MM-dd\n```\n\n## GlideSystem - getDateTimeFormat\\(\\)\n\nReturns the date and time format associated with the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The date and time format associated with the current user.|\n\nThe following example returns the format of the date and time that is associated with the user.\n\n```\nvar userDateTimeFormat = gs.getDateTimeFormat();\ngs.info(userDateTimeFormat);\n\n```\n\nOutput:\n\n```\nyyyy-MM-dd HH:mm:ss\n```\n\n## GlideSystem - getDisplayColumn\\(String tableName\\)\n\nRetrieves the display column for the table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|tableName|String|Name of the table from which to get the display column name.|\n\n|Type|Description|\n|----|-----------|\n|String|Display column name|\n\n```\n// Return the sys_id value for a given table and its display value\nfunction GetIDValue(table, displayValue) { \n    var rec = new GlideRecord(table);\n    var dn = gs.getDisplayColumn(table);\n    if (rec.get(dn, displayValue))\n        return rec.sys_id;\n    else\n        return null;\n}\n```\n\n## GlideSystem - getDisplayValueFor\\(String tableName, String recordID, String fieldName\\)\n\nReturns the display value for a specified field on a specified record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|tableName|String|Name of the table.|\n|recordID|String|Sys\\_id for the record.|\n|fieldName|String|Name of the field whose display value to return.|\n\n|Type|Description|\n|----|-----------|\n|String|Display value for the field.|\n\nThis example shows how to use getDisplayValueFor\\(\\) to return the display value of the *number* field.\n\n```\nvar value = gs.getDisplayValueFor(current.getTableName(),current.getValue('sys_id'),'number');\n\n```\n\n## GlideSystem - getErrorMessages\\(\\)\n\nReturns the list of error messages for the session that were added by addErrorMessage\\(\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|List of error messages|\n\nThis example shows how to parse through and pass back error messages using getErrorMessages\\(\\).\n\n```\nMySessionUtil.getSessionError = function() {\n  var msg = null;\n  var msgs = gs.getErrorMessages().toArray();\n  if (msgs.length > 0) {\n    msg = msgs[0] + '';\n    gs.flushMessages();\n  }\n  return msg;\n};\n\n```\n\n### Scoped equivalent\n\nTo use the getErrorMessages\\(\\) method in a scoped application, use the corresponding scoped method: [getErrorMessages\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - getEscapedProperty\\(String key, Object substituteObject\\)\n\nRetrieves the property and escapes it for XML parsing.\n\n|Name|Type|Description|\n|----|----|-----------|\n|key|String|Key for the property whose value should be returned.|\n|substituteObject|Object|Optional. Object to return if the property is not found.|\n\n|Type|Description|\n|----|-----------|\n|String|Property, or the substituteObject if the property is not found.|\n\n```\nvar propValue = gs.getEscapedProperty(\"com.example.my_test_property\");\ngs.addInfoMessage(\"This is my property value \" + propValue);\n```\n\n## GlideSystem - getImpersonatingUserDisplayName\\(\\)\n\nReturns the display name of the impersonating user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Display name of the impersonating user.|\n\nThis example shows how to obtain the impersonator's user display name.\n\n```\nvar user = gs.getUserDisplayName();\ngs.print (\"The current user display name is: \" + user);\n\nvar name = gs.getImpersonatingUserDisplayName(); \ngs.print(\"Impersonating user display name: \" + name);\n```\n\nOutput:\n\n```\nThe current user display name is: abel.tuter\nImpersonating user display name: admin\n```\n\n## GlideSystem - getImpersonatingUserName\\(\\)\n\nReturns the name of the impersonating user or null if not impersonating.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Name of impersonating user|\n\nThis example shows how to obtain the impersonator's user name.\n\n```\nvar name = gs.getImpersonatingUserName();\nvar actual_user = null;\nif (name == null || name == '')\n  actual_user = user;\nelse\n  actual_user = Packages.com.glide.sys.User.getUser(name);\n\nvar recent_impersonations = actual_user.getPreference('recent.impersonations');\nvar admin_role=actual_user.hasRole(\"admin\");\n```\n\n## GlideSystem - getInfoMessages\\(\\)\n\nRetrieves the list of info messages for the session that were added by addInfoMessage\\(\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|List of info messages.|\n\nThis example shows how to obtain the information messages.\n\n```\nvar messages = gs.getInfoMessages();\nif (messages.toString().indexOf('Conflicts Detected') == -1)\n  gs.addInfoMessage(msg);\n```\n\n## GlideSystem - getInitials\\(\\)\n\nReturns the user's initials.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The user's initials.|\n\n```\nvar userInitials = gs.getUser().getInitials();        \ngs.addInfoMessage('User initials: ' + userInitials);\n```\n\nOutput:\n\n```\nUser initials: SA\n```\n\n## GlideSystem - getMessage\\(String messageID, Object args\\)\n\nRetrieves translated messages from the Message \\[sys\\_ui\\_message\\] table to display in a UI.\n\nIf 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.\n\nFor additional information about the Message table, see [Message table](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_MessageTable.md).\n\n**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\\).\n\n<table id=\"table_czl_5j5_lt\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nmessageID\n\n</td><td>\n\nString\n\n</td><td>\n\nMessage 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.\n\n</td></tr><tr><td>\n\nargs\n\n</td><td>\n\nObject\n\n</td><td>\n\nOptional. 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);`\n\n In this example *'\\{0\\}'* is replaced with the content of *current.action.name*.\n\n **Note:** The passed in values are not translated. They are inserted verbatim in the message.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Requested UI message.|\n\nThis example shows the message returned for the current user when Spanish is the current language.\n\n```\nvar my_message = gs.getMessage(\"rows will not be updated\");\nalert(my_message);\n```\n\nOutput:\n\n```\nlas filas no se actualizarán\n```\n\nThis example shows how to replace a single variable within a message.\n\n```\n// current.action.name is \"update record\"\nvar my_message = gs.getMessage(\"Abort adding action '{0}', same subflow can't be added twice in this subflow.\", current.action.name);\nalert(my_message);\n```\n\nOutput:\n\n```\nAbort adding action update record, same subflow can't be added twice in this subflow.\n```\n\nThis example shows how to replace multiple variables within a message.\n\n```\n// current.sub_flow.name is 'schedule users'\n// current.action.name is \"update record\"\nvar 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]);\nalert(my_message);\n```\n\nOutput:\n\n```\nAbort adding action update record, same subflow can't be added twice in schedule users subflow.\n```\n\n### Scoped equivalent\n\nTo use the getMessage\\(\\) method in a scoped application, use the corresponding scoped method: [getMessage\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - getMessageS\\(String messageID, Object args\\)\n\nRetrieves translated messages to display in the UI and escapes all ticks \\('\\).\n\nIf 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.\n\nFor additional information about the Message table, see [Message table](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_MessageTable.md).\n\nUseful if you are inserting into a JavaScript expression from Jelly.\n\n<table id=\"table_gyt_xk5_lt\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nMessageID\n\n</td><td>\n\nString\n\n</td><td>\n\nMessage 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.\n\n</td></tr><tr><td>\n\nargs\n\n</td><td>\n\nObject\n\n</td><td>\n\nOptional. 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);`\n\n In this example *'\\{0\\}'* is replaced with the content of *current.action.name*.\n\n **Note:** The passed in values are not translated. They are inserted verbatim in the message.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Specified message with ticks escaped.|\n\n```\n/*\n\"I love France\" translates to \"J'aime la France\" in French.\nRendering this without escaping the tick in \"J'aime\" would break Jelly, because \nthe tick would prematurely end the variable assignment, and everything that \nfollows (aime la France') would be a jelly syntax error.\n*/\nvar my_message = '${gs.getMessageS(\"I love France\")}'; \nalert(my_message);\n```\n\nOutput:\n\n```\nJ'aime la France\n```\n\n## GlideSystem - getMessageLang\\(String message, String language, Array args\\)\n\nTranslates the specified message into the specified language.\n\nYou can also embed variables in the passed message. The method resolves those variables with the values passed in the **args** array.\n\n<table id=\"table_m4v_3tl_zyb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nmessage\n\n</td><td>\n\nString\n\n</td><td>\n\nMessage to translate.\n\n</td></tr><tr><td>\n\nlanguage\n\n</td><td>\n\nString\n\n</td><td>\n\nLanguage in which to translate the message.Format: BCP 47 standard\n\n</td></tr><tr><td>\n\nargs\n\n</td><td>\n\nArray\n\n</td><td>\n\nOptional. 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);`\n\nIn this example *'\\{0\\}'* is replaced with the content of *current.action.name*.\n\n**Note:** The passed in values are not translated. They are inserted verbatim in the message.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Translated message.|\n\nThe following example transforms the specified message into Spanish.\n\n```\nvar my_message = gs.getMessageLang(\"New email\", \"es\");\ngs.info(my_message);\n```\n\nOutput:\n\n```\nNuevo correo electrónico\n```\n\nThe following example shows how to replace variables within a message.\n\n```\nvar my_message = gs.getMessageLang(\"There are {0} new emails for {1}\", \"es\", [current.numEmails, current.userName]);\ngs.info(my_message);\n```\n\nOutput:\n\n```\nHay 7 correos nuevos para John Smith\n```\n\n## GlideSystem - getNodeName\\(Object obj, Number index\\)\n\nReturns the node name for the specified index.\n\n|Name|Type|Description|\n|----|----|-----------|\n|obj|Object|Object to examine.|\n|index|Number|Index from which to obtain the node name.|\n\n|Type|Description|\n|----|-----------|\n|String|Node's name|\n\n```\nfunction doInsert(nodeList) {\n  gs.print('Doing insert');\n  var task = new GlideRecord('task');\n  task.initialize();\n  for (var x=0; x < nodeList.size(); x++) {\n    var name = gs.getNodeName(nodeList, x);\n    var value = gs.getNodeValue(nodeList, x);\n    task.setValue(name, value);\n  }\n  task.insert();\n}\n```\n\n## GlideSystem - getNodeValue\\(Object obj, Number index\\)\n\nReturns the node value for the specified index.\n\n|Name|Type|Description|\n|----|----|-----------|\n|obj|Object|Object to examine.|\n|index|Number|Index from which to get the node valu.e|\n\n|Type|Description|\n|----|-----------|\n|Object|Node value|\n\n```\nfunction doInsert(nodeList) {\n  gs.print('Doing insert');\n  var task = new GlideRecord('task');\n  task.initialize();\n  for (var x=0; x < nodeList.size(); x++) {\n    var name = gs.getNodeName(nodeList, x);\n    var value = gs.getNodeValue(nodeList, x);\n    task.setValue(name, value);\n  }\n  task.insert();\n}\n```\n\n## GlideSystem - getPreference\\(String key, Object default\\)\n\nReturns the specified user preference.\n\n|Name|Type|Description|\n|----|----|-----------|\n|key|String|Key for the preference.|\n|default|Object|Default value to use if the specified preference is not found.|\n\n|Type|Description|\n|----|-----------|\n|String|Preference value. If no preference, returns the specified default value.|\n\n```\nfunction getSelectedProject() {\n  var array= new Array();\n  var prj_id = gs.getPreference(\"prj_id\"); //This will fetch value from user preference\n  var gr = new GlideRecord('pm_project_task');\n  gr.addQuery('parent', prj_id);\n  gr.addActiveQuery();\n  while(gr.next()) {\n    array.push(gr.sys_id.toString());\n  }\n  return array;\n}\n```\n\n## GlideSystem - getProperty\\(String key, Object alt\\)\n\nReturns the value of a Glide property. If the property is not found, returns the specified **alt** value.\n\n|Name|Type|Description|\n|----|----|-----------|\n|key|String|Key for the property whose value should be returned.|\n|alt|Object|Optional. Alternate object to return if the property is not found.|\n\n|Type|Description|\n|----|-----------|\n|String|Value of the Glide property, or the alternate object defined above.|\n\n```\n//Check for attachments and add link if there are any\nvar attachment_link = '';\nvar rec = new GlideRecord('sc_req_item');\nrec.addQuery('sys_id', current.request_item);\nrec.query();\nif(rec.next()){\n  if(rec.hasAttachments()){\n    attachment_link = gs.getProperty('glide.servlet.uri') + rec.getLink();\n  }   \n}\n```\n\n## GlideSystem - getScriptError\\(String script\\)\n\nReturns the script error found in the specified script, if there is one.\n\n**Note:** The script is not executed by this function, it is only checked for syntax errors.\n\n|Name|Type|Description|\n|----|----|-----------|\n|script|String|Script to check for errors.|\n\n|Type|Description|\n|----|-----------|\n|String|Error message. Null if there is no error.|\n\n```\nif (gs.isValidScript(current.script) == false)\n  {\n    current.setAbortAction(true);\n    var error = gs.getScriptError(current.script);\n    current.script.setError(error);\n  }\n```\n\n## GlideSystem - getSession\\(\\)\n\nReturns a GlideSession object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|GlideSession Object|GlideSession object for the current session|\n\n```\nif(!gs.hasRole(\"admin\") && gs.getSession().isInteractive() && gs.getUserName() != \"guest\"){\n  var qc = current.addQuery('u_visibility', \"both\");\n  qc.addOrCondition('u_visibility', '');\n  if (gs.getImpersonatingUserName() != null) {\n    gs.getSession().clearClientData('navQuery');\n  }\n  var navQuery = gs.getSession().getClientData('navQuery');\n  if (navQuery == null) {\n    var isManager = gs.getUser().getRecord().getValue('u_is_manager');\n      if (!isManager) {\n        qc.addOrCondition('u_visibility', 'nonmanager');\n        gs.getSession().putClientData('navQuery', 'nonmanager');\n      } else {\n        qc.addOrCondition('u_visibility', 'manager');\n        gs.getSession().putClientData('navQuery', 'manager');\n        }\n  } else {\n  qc.addOrCondition('u_visibility', navQuery);\n  }   \n}\n```\n\n### Scoped equivalent\n\nTo use the getSession\\(\\) method in a scoped application, use the corresponding scoped method: [getSession\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - getSessionID\\(\\)\n\nReturns the GlideSession session ID.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Session ID|\n\n```\nvar gr_NOW = new GlideRecord('v_user_session');\nvar sessionId = gs.getSessionID();\ngs.log(\"Session ID is: \" + sessionId);\n```\n\nOutput\n\n```\nSession ID is: FEE589B3DB7EE4103DD9C39D139619D7\n```\n\n### Scoped equivalent\n\nTo use the getSessionID\\(\\) method in a scoped application, use the corresponding scoped method: [getSessionID](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - getStyle\\(String tableName, String fieldName, String fieldValue\\)\n\nReturns the style defined for the table, field, and field value.\n\n|Name|Type|Description|\n|----|----|-----------|\n|tableName|String|Table name|\n|fieldName|String|Field name|\n|fieldValue|String|Field value|\n\n|Type|Description|\n|----|-----------|\n|String|Style of the specified field.|\n\n```\nvar returnString = gs.getStyle('<tableName>', '<fieldName>', '<fieldValue>');\ngs.print(returnString);\n```\n\n## GlideSystem - getTimeFormat\\(\\)\n\nReturns the time format associated with the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Time format associated with the current user.|\n\nThe following code example shows how to call this method.\n\n```\nvar userTimeFormat = gs. getTimeFormat();\ngs.info(userTimeFormat);\n\n```\n\nOutput:\n\n```\nHH:mm:ss\n```\n\n## GlideSystem - getUser\\(\\)\n\nReturns a reference to the user object for the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|GlideUser|Reference to a user object for the current user.|\n\nThe following example shows how to get the current user object.\n\n```\nvar user = gs.getUser();\ngs.print (\"The current user is: \" + user);\n```\n\nOutput:\n\n```\nThe current user is: com.glide.sys.User@db5dd9\n```\n\nThe following example shows how to check whether the current user has the workflow\\_admin role.\n\n```\nvar role = gs.getUser().hasRole('workflow_admin');\ngs.print (\"Does the current user have the workflow_admin role: \" + role);\n```\n\nOutput:\n\n```\nDoes the current user have the workflow_admin role: true\n```\n\n### Scoped equivalent\n\nTo use the getUser\\(\\) method in a scoped application, use the corresponding scoped method: [getUser\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - getUserDisplayName\\(\\)\n\nGets the display name of the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_nvv_vjb_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nThe name field of the current user. For example, this method returns Abel Tuter as opposed to abel.tuter.\n\n</td></tr></tbody>\n</table>This example gets the current user's display name.\n\n```\ngs.info(gs.getUserDisplayName());\n```\n\nOutput:\n\n```\nSystem Administrator\n```\n\n### Scoped equivalent\n\nTo use the getUserDisplayName\\(\\) method in a scoped application, use the corresponding scoped method: [getUserDisplayName\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - getUserID\\(\\)\n\nReturns the sys\\_id of the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the current user.|\n\nThis example gets the current user's sys\\_id.\n\n```\nvar currentUserId = gs.getUserID();\ngs.print(\"Current user ID: \" + currentUserId);\n```\n\nOutput:\n\n```\nCurrent user ID: 6816f79cc0a8016401c5a33be04be441\n```\n\n### Scoped equivalent\n\nTo use the getUserID\\(\\) method in a scoped application, use the corresponding scoped method: [getUserID\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - getUserName\\(\\)\n\nReturns the user name of the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_bpf_plb_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nThe user name of the current user.For example, this method returns abel.tuter as opposed to Abel Tuter.\n\n</td></tr></tbody>\n</table>This example gets the user name of the current user and an impersonated user.\n\n```\nvar user = gs.getUserName();\ngs.info(\"The current user name is: \" + user);\n\nvar impUser = new GlideImpersonate();\nimpUser.impersonate(\"62826bf03710200044e0bfc8bcbe5df1\");\nvar user2 = gs.getUserName();\ngs.info(\"The impersonated user name is: \" + user2);\n```\n\nOutput:\n\n```\nThe current user name is: admin\nThe impersonated user name is: abel.tuter\n```\n\n### Scoped equivalent\n\nTo use the getUserName\\(\\) method in a scoped application, use the corresponding scoped method: [getUserName\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - getUserNameByUserID\\(String user\\_id\\)\n\nReturns the user display name based on a provided user login name.\n\n|Name|Type|Description|\n|----|----|-----------|\n|user\\_id|String|Login name of the user from which to retrieve the associated display name.|\n\n<table id=\"table_pp4_1mb_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nDisplay name of the requested user.**Note:** If this method can't find a user with the requested ID, it returns the input value provided.\n\n</td></tr></tbody>\n</table>The following example shows how to get the specified user's display name.\n\n```\nvar displayName = gs.getUserNameByUserID('abel.tuter');\ngs.info('User display name is: ' + displayName);\n```\n\nOutput:\n\n```\nUser display name is: Abel Tuter\n```\n\n## GlideSystem - getXMLNodeList\\(String xml\\)\n\nConstructs an array of all the nodes and values in an XML document.\n\n|Name|Type|Description|\n|----|----|-----------|\n|xml|String|XML document to parse.|\n\n|Type|Description|\n|----|-----------|\n|Array list|List of names and values of the outer most XML node.|\n\nThe following example shows how to get a list of XML nodes and their associated values in an array list.\n\n```\nvar nodeList = gs.getXMLNodeList(\"<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>\");\ngs.print (\"The node contains: \" + nodeList);\n\n```\n\nOutput:\n\n```\nThe node contains: [to : Tove, from : Jani, heading : Reminder, body : Don't forget me this weekend!]\n\n```\n\n## GlideSystem - getXMLText\\(String xml, String xpathQuery\\)\n\nReturns the XML text for the first element in the XML string that matches the XPath query.\n\n|Name|Type|Description|\n|----|----|-----------|\n|xml|String|XML string to search.|\n|xpathQuery|String|XPath query to match.|\n\n|Type|Description|\n|----|-----------|\n|String|XML node matching the search parameters.|\n\nThe following example shows how to get the value of a specified XML element within a passed-in node.\n\n```\nvar 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\");\ngs.print (\"The from element contains: \" + nodeList);\n```\n\nOutput:\n\n```\nThe from element contains: Jani\n```\n\n## GlideSystem - hasRole\\(String roleName\\)\n\nDetermines if the current user has at least one of the passed-in roles.\n\n|Name|Type|Description|\n|----|----|-----------|\n|roleName|String|Comma-separated list of roles.|\n\n<table id=\"table_cyk_5nb_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the current user has at least one of the specified roles.Possible values:\n\n-   true: User has at least one of the passed-in roles. Also returns true if the user has the administrator role.\n-   false: User does not have any of the passed-in roles.\n\n</td></tr></tbody>\n</table>The following example shows how to check whether the current user has the admin or groups\\_admin role.\n\n```\nif (!gs.hasRole(\"admin, groups_admin\") && gs.getSession().isInteractive()) {\n  var qc = current.addQuery(\"u_hidden\", \"!=\", \"true\"); //cannot see hidden groups... \n  qc.addOrCondition(\"sys_id\", \"javascript:getMyGroups()\"); //...unless in the hidden group\n}\n```\n\n### Scoped equivalent\n\nTo use the hasRole\\(\\) method in a scoped application, use the corresponding scoped method: [hasRole\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - hasRoleInGroup\\(Object roleName, Object group\\)\n\nDetermines if the current user has the specified role within a specified group.\n\n|Name|Type|Description|\n|----|----|-----------|\n|roleName|Object|Name of the role.|\n|group|Object|Sys\\_id of the group to check for the specified role.|\n\n<table id=\"table_eys_m4b_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the current user has the specified role in the specified group.Possible values:\n\n-   true: The logged-in user is assigned to the specified role in the specified group.\n-   false: The logged-in user is not assigned to the specified role in the specified group.\n\n</td></tr></tbody>\n</table>The following example shows how to check whether the sys\\_user\\_group group has the role\\_name role.\n\n```\nvar group = new GlideRecord('sys_user_group');\ngroup.addQuery('name', 'GROUP_NAME');\ngroup.setLimit(1);\ngroup.query();\nif (group.next()) {\n   if (gs.hasRoleInGroup('role_name', group)) {\n      gs.print('User has role in group');  \n   } else {\n      gs.print('User does NOT have role in group');\n   }  \n}\n```\n\n## GlideSystem - hoursAgo\\(Number hours\\)\n\nReturns a date and time for the specified number of hours ago. The returned value is adjusted for the time zone of the instance.\n\n|Name|Type|Description|\n|----|----|-----------|\n|hours|Number|Number of hours ago.|\n\n<table id=\"table_wrq_j1x_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC date and time for the specified number of hours ago. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>```\nvar currentDateTime = gs.hoursAgo(0);\ngs.info(\"Current date/time: \" + currentDateTime);\n\nvar agoDateTime = gs.hoursAgo(1);\ngs.info(\"Ago date/time: \" + agoDateTime);\n```\n\nOutput\n\n```\nCurrent date/time: 2021-03-17 20:53:25\nAgo date/time: 2021-03-17 19:53:25\n```\n\n### Scoped equivalent\n\nTo use the hoursAgo\\(\\) method in a scoped application, use the corresponding scoped method: [hoursAgo\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - hoursAgoEnd\\(Number hours\\)\n\nReturns 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|hours|Number \\(Integer\\)|Number of hours ago.|\n\n<table id=\"table_edc_v1x_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC date and time for the end of the specified number of hours ago. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>```\nvar currentDateTime = gs.hoursAgoEnd(0);\ngs.print(\"Current date/time: \" + currentDateTime);\n\nvar agoDateTime = gs.hoursAgoEnd(1);\ngs.print(\"Ago date/time: \" + agoDateTime);\n```\n\nOutput\n\n```\nCurrent date/time: 2021-03-17 20:59:59\nAgo date/time: 2021-03-17 19:59:59\n```\n\n### Scoped equivalent\n\nTo use the hoursAgoEnd\\(\\) method in a scoped application, use the corresponding scoped method: [hoursAgoEnd\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - hoursAgoStart\\(Number hours\\)\n\nReturns 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|hours|Number|Number of hours ago.|\n\n<table id=\"table_xwb_xbx_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC date and time for the end of the specified number of hours ago. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>```\nvar currentDateTime = gs.hoursAgoStart(0);\ngs.print(\"Current date/time: \" + currentDateTime);\n\nvar agoDateTime = gs.hoursAgoStart(1);\ngs.print(\"Ago date/time: \" + agoDateTime);\n```\n\nOutput\n\n```\nCurrent date/time: 2021-03-17 20:00:00\nAgo date/time: 2021-03-17 19:00:00\n```\n\n### Scoped equivalent\n\nTo use the hoursAgoStart\\(\\) method in a scoped application, use the corresponding scoped method: [hoursAgoStart\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - isFirstDayOfMonth\\(Object date\\)\n\nChecks whether the date in the specified date object is the first day of the month.\n\n|Name|Type|Description|\n|----|----|-----------|\n|date|Object|Date object on which to check the date, such as GlideDateTime or GlideDate.|\n\n<table id=\"table_qyc_x3x_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the date in the specified date object is the first day of the month.Possible values:\n\n-   true: First day of the month.\n-   false: Not the first day of the month.\n\n</td></tr></tbody>\n</table>This example show how to determine whether the date in the specified date object is the first day of the month.\n\n```\nvar gdt = new GlideDateTime();\ngdt.setValue('2021-04-01 12:00:00');\nvar currentDay = gs.isFirstDayOfMonth(gdt);\ngs.print(\"First day of month: \" + currentDay);\n\ngdt.setValue('2021-04-21 12:00:00');\nvar currentDay = gs.isFirstDayOfMonth(gdt);\ngs.print(\"First day of month: \" + currentDay);\n```\n\nOutput\n\n```\nFirst day of month: true\nFirst day of month: false\n```\n\n## GlideSystem - isFirstDayOfWeek\\(Object date\\)\n\nChecks 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|date|Object|Date object on which to check the date, such as GlideDateTime or GlideDate.|\n\n<table id=\"table_ew2_hjx_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the date in the current date object is the first day of the week \\(Monday\\).Possible values:\n\n-   true: First day of the week.\n-   false: Not the first day of the week.\n\n</td></tr></tbody>\n</table>This example show how to determine whether the date in the specified date object is the first day of the week.\n\n```\nvar gdt = new GlideDateTime();\ngdt.setValue('2021-03-02 12:00:00');\nvar currentDay = gs.isFirstDayOfWeek(gdt);\ngs.info(\"First day of week: \" + currentDay);\n\ngdt.setValue('2021-03-22 12:00:00');\nvar currentDay = gs.isFirstDayOfWeek(gdt);\ngs.info(\"First day of week: \" + currentDay);\n```\n\nOutput\n\n```\nFirst day of week: false\nFirst day of week: true\n```\n\n## GlideSystem - isFirstDayOfYear\\(Object date\\)\n\nChecks whether the date in the specified date object is the first day of the year.\n\n|Name|Type|Description|\n|----|----|-----------|\n|date|Object|Date object on which to check the date, such as GlideDateTime or GlideDate.|\n\n<table id=\"table_vrv_sjx_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the date in the specified date object is the first day of the year.Possible values:\n\n-   true: First day of the year.\n-   false: Not the first day of the year.\n\n</td></tr></tbody>\n</table>This example show how to determine whether the date in the specified date object is the first day of the year.\n\n```\nvar gdt = new GlideDateTime();\ngdt.setValue('2020-12-31 12:00:00');\nvar currentDay = gs.isFirstDayOfYear(gdt);\ngs.info(\"First day of year: \" + currentDay);\n\ngdt.setValue('2021-01-01 12:00:00');\nvar currentDay = gs.isFirstDayOfYear(gdt);\ngs.info(\"First day of year: \" + currentDay);\n```\n\nOutput\n\n```\nFirst day of year: false\nFirst day of year: true\n```\n\n## GlideSystem - isInteractive\\(\\)\n\nChecks if the current session is interactive.\n\nAn 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_cc5_kpb_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the session is interactive.Possible values:\n\n-   true: Session is interactive.\n-   false: Session is not interactive.\n\n</td></tr></tbody>\n</table>```\nif (!gs.hasRole('admin') && gs.isInteractive()) {\n  var qc1 = current.addQuery('u_group', '');\n  var gra = new GlideRecord('sys_user_grmember');\n  gra.addQuery('user', gs.getUserID());\n  gra.query();\n  while (gra.next()) {\n    qc1.addOrCondition('u_group', gra.group);\n  }\n}\n```\n\n### Scoped equivalent\n\nTo use the isInteractive\\(\\) method in a scoped application, use the corresponding scoped method: [isInteractive\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - isLastDayofMonth\\(Object date\\)\n\nChecks whether the date in the specified date object is the last day of the month.\n\n|Name|Type|Description|\n|----|----|-----------|\n|date|Object|Date object on which to check the date, such as GlideDateTime or GlideDate.|\n\n<table id=\"table_h2y_ckx_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the date in the specified date object is the last day of the month.Possible values:\n\n-   true: Last day of the month.\n-   false: Not the last day of the month.\n\n</td></tr></tbody>\n</table>This example show how to determine whether the date in the specified date object is the last day of the month.\n\n```\nvar gdt = new GlideDate();\ngdt.setValue('2020-12-31 12:00:00');\nvar currentDay = gs.isLastDayOfMonth(gdt);\ngs.print(\"First day of year: \" + currentDay);\n\ngdt.setValue('2021-01-01 12:00:00');\nvar currentDay = gs.isLastDayOfMonth(gdt);\ngs.print(\"First day of year: \" + currentDay);\n```\n\nOutput\n\n```\nLast day of month: true\nLast day of month: false\n```\n\n## GlideSystem - isLastDayOfWeek\\(Object date\\)\n\nChecks 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|date|Object|Date object on which to check the date, such as GlideDateTime or GlideDate.|\n\n<table id=\"table_e55_nkx_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the date in the current date object is the last day of the week \\(Sunday\\).Possible values:\n\n-   true: Last day of the week.\n-   false: Not the last day of the week.\n\n</td></tr></tbody>\n</table>This example show how to determine whether the date in the specified date object is the last day of the week.\n\n```\nvar gdt = new GlideDate();\ngdt.setValue('2021-03-01 12:00:00');\nvar currentDay = gs.isLastDayOfWeek(gdt);\ngs.info(\"Last day of week: \" + currentDay);\n\ngdt.setValue('2021-03-21 12:00:00');\nvar currentDay = gs.isLastDayOfWeek(gdt);\ngs.info(\"Last day of week: \" + currentDay);\n```\n\nOutput\n\n```\nFirst day of week: false\nFirst day of week: true\n```\n\n## GlideSystem - isLastDayOfYear\\(Object date\\)\n\nChecks whether the date in the specified date object is the last day of the year.\n\n|Name|Type|Description|\n|----|----|-----------|\n|date|Object|Date object on which to check the date, such as GlideDateTime or GlideDate.|\n\n<table id=\"table_d2t_xkx_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the date in the current date object is the last day of the year.Possible values:\n\n-   true: Last day of the year.\n-   false: Not the last day of the year.\n\n</td></tr></tbody>\n</table>This example show how to determine whether the date in the specified date object is the last day of the year.\n\n```\nvar gdt = new GlideDateTime();\ngdt.setValue('2020-12-31 12:00:00');\nvar currentDay = gs.isLastDayOfYear(gdt);\ngs.info(\"Last day of year: \" + currentDay);\n\ngdt.setValue('2021-01-01 12:00:00');\nvar currentDay = gs.isLastDayOfYear(gdt);\ngs.info(\"Last day of year: \" + currentDay);\n```\n\nOutput\n\n```\nLast day of year: true\nLast day of year: false\n```\n\n## GlideSystem - isLoggedIn\\(\\)\n\nDetermines if the current user is currently logged in.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_kdh_5pb_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the current user is logged in.Possible values:\n\n-   true: User is logged in.\n-   false: User is not logged in.\n\n</td></tr></tbody>\n</table>This example show how to determine whether the current user is logged in.\n\n```\nif(gs.isLoggedIn())\n  gs.info(\"Current user is logged in\");\nelse\n  gs.info(\"Current user is NOT logged in\");\n```\n\nOutput\n\n```\nCurrent user is logged in\n```\n\n### Scoped equivalent\n\nTo use the isLoggedIn\\(\\) method in a scoped application, use the corresponding scoped method: [isLoggedIn\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - isMobile\\(\\)\n\nDetermines whether the request came from a mobile device.\n\nYou can use this method in UI action conditions and business rules.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_hnw_lbz_bv\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the request came from a mobile device.Possible values:\n\n-   true: Mobile device.\n-   false: Non-mobile device.\n\n</td></tr></tbody>\n</table>This example show how to determine whether the current device is a mobile device.\n\n```\nif(gs.isMobile())\n    gs.info(\"Submitted from mobile UI\");\n  else \n   gs.info(\"NOT submitted from mobile UI\");\n```\n\nOutput\n\n```\nSubmitted from mobile UI\n```\n\n### Scoped equivalent\n\nTo use the isMobile\\(\\) method in a scoped application, use the corresponding scoped method: [isMobile\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - lastWeek\\(\\)\n\nReturns the date and time one week ago in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_usk_mcx_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nDate and time one week ago. Format: \\(UTC\\) yyyy-MM-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example show how to obtain the date that is one week from the date in the current date object.\n\n```\nvar gdt = new GlideDateTime();\ngdt.setValue('2021-03-22 01:00:00');\n\ngs.info(\"Current date: \" + gs.nowDateTime());\n\ngs.info(\"One week earlier: \" + gs.lastWeek());\n```\n\nOutput\n\n```\nCurrent date: 2021-03-22 15:27:07\nOne week earlier: 2021-03-15 15:27:07\n```\n\n## GlideSystem - log\\(String message, String source\\)\n\nLogs a message to the system log and saves it to the syslog table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|Message to log.|\n|source|String|Optional. Source of the message.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how to post a log entry using constants and variables.\n\n```\nvar count = new GlideAggregate('incident');\ncount.addQuery('active', 'true');\ncount.addAggregate('COUNT', 'category');\ncount.query();   \nwhile (count.next()) {\n   var category = count.category;\n   var categoryCount = count.getAggregate('COUNT', 'category');\n   gs.log(\"The are currently \" + categoryCount + \" incidents with a category of \" + category, \"Incident Counter\");\n}\n```\n\n## GlideSystem - logError\\(String message, String source\\)\n\nLogs an error to the system log and saves it to the syslog table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|Error message to log.|\n|source|String|Optional. Source of the message.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example logs an error if the Incident table cannot be found.\n\n```\nvar gr_NOW = new GlideRecord(\"incident\");\nif (!gr_NOW.isValid()) {\n  gs.logError('Incident table could not be found');\n  return;\n}\n```\n\n## GlideSystem - logWarning\\(String message, String source\\)\n\nLogs a warning to the system log and saves it to the syslog table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|Message to log.|\n|source|String|Optional. Source of the message.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example logs a warning if the Incident table cannot be found.\n\n```\nvar gr_NOW = new GlideRecord(\"incident\");\nif (!gr_NOW.isValid()) {\n  gs.logWarning('Incident table could not be found');\n  return;\n}\n```\n\n## GlideSystem - minutesAgo\\(Number minutes\\)\n\nReturns a date and time for the specified number of minutes ago.\n\n|Name|Type|Description|\n|----|----|-----------|\n|minutes|Number|Number of minutes in the past to return.|\n\n<table id=\"table_hnh_vcx_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC date and time for the specified number of minutes ago. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>This example shows how to use the minutesAgo\\(\\) method in an addQuery\\(\\) call.\n\n```\n// Check to see if the user has failed to login too many times\n// when the limit is reached, lock the user out of the system\n//\n//Check failed logins in the last 15 minutes\nvar now_GR = new GlideRecord('sysevent');\nnow_GR.addQuery('name', 'login.failed');\nnow_GR.addQuery('parm1', event.parm1.toString());\nnow_GR.addQuery('sys_created_on','>=', gs.minutesAgo(15));\nnow_GR.query();\nvar rowCount = now_GR.getRowCount();\nif(rowCount >= 5){\n  var now_GR = new GlideRecord(\"sys_user\");\n  now_GR.addQuery(\"user_name\", event.parm1.toString());\n  now_GR.query();\n  if (now_GR.next()) {\n    now_GR.locked_out = true;\n    now_GR.update();\n    gs.log(\"User \" + event.parm1 + \" locked out due to too many invalid login attempts\");\n  }\n}\n```\n\n## GlideSystem - minutesAgoEnd\\(Number minutes\\)\n\nReturns a date and time for the end of the minute a certain number of minutes ago. Returned in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|minutes|Number|Integer number of minutes ago, such as 5 or 11.|\n\n<table id=\"table_gp2_hdx_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC the specified number of minutes ago, at the end of the minute \\(59 seconds\\). Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>The following example displays the current date and time and the date and time 30 minutes ago at the end of the minute in UTC.\n\n```\nvar nowDateTime = new GlideDateTime();\ngs.print(\"Now: \" + nowDateTime);\nvar thirtyMinutesAgoDateTime = gs.minutesAgoEnd(30);\ngs.print(\"Thirty minutes ago end time: \" + thirtyMinutesAgoDateTime);\n```\n\nOutput:\n\n```\nNow: 2021-10-20 15:22:13\nThirty minutes ago end time: 2021-10-20 14:52:59\n```\n\n### Scoped equivalent\n\nTo use the minutesAgoEnd\\(\\) method in a scoped application, use the corresponding scoped method: [minutesAgoEnd\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - minutesAgoStart\\(Number minutes\\)\n\nReturns a date and time for the start of the minute a certain number of minutes ago. Returned in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|minutes|Number|Integer number of minutes ago, such as 15 or 112.|\n\n<table id=\"table_yzm_tdx_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC the specified number of minutes ago, at the start of the minute. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>The following example displays the current date and time and the date and time 30 minutes ago at the start of the minute in UTC.\n\n```\nvar nowDateTime = new GlideDateTime();\ngs.info(\"Now: \" + nowDateTime);\nvar thirtyMinutesAgoDateTime = gs.minutesAgoStart(30);\ngs.info(\"Thirty minutes ago: \" + thirtyMinutesAgoDateTime);\n```\n\nOutput:\n\n```\nNow: 2021-10-20 14:56:18\nThirty minutes ago: 2021-10-20 14:26:00\n```\n\n### Scoped equivalent\n\nTo use the minutesAgoStart\\(\\) method in a scoped application, use the corresponding scoped method: [minutesAgoStart\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - monthsAgo\\(Number months\\)\n\nReturns a date and time for a certain number of months ago in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|months|Number|Integer number of months ago.|\n\n<table id=\"table_qhw_f2x_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC of the specified number of months ago at the exact same time.Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>The following example displays the current date and time and the date and time one month ago at the same time in UTC.\n\n```\nvar nowDateTime = new GlideDateTime();\ngs.info(\"Now: \" + nowDateTime);\nvar oneMonthAgoDateTime = gs.monthsAgo(1);\ngs.info(\"One month ago: \" + oneMonthAgoDateTime);\n```\n\nOutput:\n\n```\nNow: 2021-10-20 15:29:15\nOne month ago: 2021-09-20 15:29:15\n```\n\n### Scoped equivalent\n\nTo use the monthsAgo\\(\\) method in a scoped application, use the corresponding scoped method: [monthsAgo\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - monthsAgoEnd\\(Number months\\)\n\nReturns the date and time for the last day of the month a specified number of months ago.\n\n|Name|Type|Description|\n|----|----|-----------|\n|months|Number \\(Integer\\)|Number of months, such as 4 or 16.|\n\n<table id=\"table_oqx_r2x_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nDate and time stamp of the month, the specified number of months ago, in local time. Format: UTC yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>The following example displays the current date and time and the date and time two months ago at the end of the business month.\n\n```\nvar nowDateTime = new GlideDateTime();\ngs.info(\"Now: \" + nowDateTime);\nvar endOfTheMonthDateTime = gs.monthsAgoEnd(2);\ngs.info(\"End of the month: \" + endOfTheMonthDateTime);\n```\n\nOutput:\n\n```\nNow: 2021-10-20 19:23:35\nEnd of the month: 2021-08-01 06:59:59\n```\n\n## GlideSystem - monthsAgoStart\\(Number months\\)\n\nReturns a date and time for the start of the month a certain number of months ago. Returned in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|months|Number|Integer number of months ago, such as 5 or 14.|\n\n<table id=\"table_ymk_bfx_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC start of the month the specified number of months ago.Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>The following example displays the current date and time and the date and time three months ago in UTC.\n\n```\nvar nowDateTime = new GlideDateTime();\ngs.info(\"Now: \" + nowDateTime);\nvar threeMonthsAgoDateTime = gs.monthsAgoStart(3);\ngs.info(\"Three months ago start date and time: \" + threeMonthsAgoDateTime);\n```\n\nOutput:\n\n```\nNow: 2021-10-20 15:05:27\nThree months ago start date and time: 2021-07-01 07:00:00\n```\n\n### Scoped equivalent\n\nTo use the monthsAgoStart\\(\\) method in a scoped application, use the corresponding scoped method: [monthsAgoStart\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - nil\\(Object obj\\)\n\nQueries an object and returns true if the object is null or contains an empty string.\n\n|Name|Type|Description|\n|----|----|-----------|\n|obj|Object|The object to be checked.|\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if null or empty string; otherwise, false.|\n\n```\nif ((!current.u_date1.nil()) && (!current.u_date2.nil())) {\n  var start = current.u_date1.getGlideObject().getNumericValue();\n  var end = current.u_date2.getGlideObject().getNumericValue();\n  if (start > end) {\n    gs.addInfoMessage('start must be before end');\n    current.u_date1.setError('start must be before end');\n    current.setAbortAction(true);\n  }\n}\n```\n\n### Scoped equivalent\n\nTo use the nil\\(\\) method in a scoped application, use the corresponding scoped method: [nil\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - now\\(\\)\n\nReturns the current date in UTC.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The current date in the user-defined format, in UTC.|\n\n```\n// When the user password changes then set the u_password_last_reset field\n// to now so we know when to force another update\n \nvar now_GR = new GlideRecord(\"sys_user\");\nif (now_GR.get(event.parm1.toString())) {\n    // Do something based on the Password Changing\n    gs.log(\"The user password changed so do something else...\");\n    now_GR.u_password_last_reset = gs.now();\n    now_GR.update();\n}\n```\n\n## GlideSystem - nowNoTZ\\(\\)\n\nReturns the current date and time in UTC format.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The current UTC date time|\n\n```\n// When the user password changes then set the u_password_last_reset field\n// to now so we know when to force another update\n \nvar now_GR = new GlideRecord(\"sys_user\");\nif (now_GR.get(event.parm1.toString())) {\n    // Do something based on the Password Changing\n    gs.log(\"The user password changed so do something else...\");\n    now_GR.u_password_last_reset = gs.nowNoTZ();\n    now_GR.update();\n}\n```\n\n## GlideSystem - nowDateTime\\(\\)\n\nReturns the current date and time in the user-defined format.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|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://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_UseDateAndTimeFields.md).|\n\n```\nvar currentDateTime = gs.nowDateTime();\ngs.print(\"Current date/time: \" + currentDateTime);\n```\n\nOutput\n\n```\nCurrent date/time: 2021-03-17 14:04:02\n```\n\nWhen 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.\n\n```\ncurrent.variables.end_date.setDisplayValue(gs.nowDateTime());\n```\n\n## GlideSystem - nowGlideDateTime\\(\\)\n\nGets a GlideDateTime object with the current date and time in the user's session time zone as a UTC timestamp.\n\nAfter 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Object|GlideDateTime object with the current date and time in UTC format.|\n\nSets the field u\\_target\\_date to the current date and time in UTC format.\n\n```\ncurrent.u_target_date = gs.nowGlideDateTime();\n```\n\n## GlideSystem - print\\(String message\\)\n\nWrites a message to the system log.\n\nThis method does not write the message to the syslog table unless debug has been activated.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|The message to log|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar rec = new GlideRecord('incident');\nrec.addQuery('active',false);\nrec.query();\nwhile (rec.next()) { \n gs.print('Inactive incident ' + rec.number + ' deleted');\n rec.deleteRecord();\n}\n```\n\n## GlideSystem - quartersAgo\\(Number quarters\\)\n\nReturns a date and time for a certain number of quarters ago in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|quarters|Number|Integer number of the quarters ago.|\n\n<table id=\"table_j12_zgx_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nUTC of the quarter that was the specified number of quarters ago. Format: yyyy-mm-dd hh:mm:ss\n\n</td></tr></tbody>\n</table>The following example displays the current date and time and the date and time four quarters ago at the same time.\n\n```\nvar nowDateTime = new GlideDateTime();\ngs.print(\"Now: \" + nowDateTime);\nvar fourQuartersAgoDateTime = gs.quartersAgo(4);\ngs.print(\"Four quarters ago: \" + fourQuartersAgoDateTime);\n```\n\nOutput:\n\n```\nNow: 2021-10-20 16:27:32\nFour quarters ago: 2020-10-20 16:27:32\n```\n\n## GlideSystem - quartersAgoEnd\\(Number quarters\\)\n\nReturns a date and time for the last day of the quarter, for a specified number of quarters ago. Returned in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|quarters|Number|An integer number of quarters|\n\n|Type|Description|\n|----|-----------|\n|String|UTC end of the quarter that was the specified number of quarters ago, in the format yyyy-mm-dd hh:mm:ss|\n\n### Scoped equivalent\n\nTo use the quartersAgoEnd\\(\\) method in a scoped application, use the corresponding scoped method: [quartersAgoEnd\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - quartersAgoStart\\(Number quarters\\)\n\nReturns a date and time for the first day of the quarter, for a specified number of quarters ago. Returned in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|quarters|Number|An integer number of quarters|\n\n|Type|Description|\n|----|-----------|\n|String|UTC end of the month that was the specified number of quarters ago, in the format yyyy-mm-dd hh:mm:ss|\n\n### Scoped equivalent\n\nTo use the quartersAgoStart\\(\\) method in a scoped application, use the corresponding scoped method: [quartersAgoStart\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - setProperty\\(String key, String value, String description\\)\n\nSets the specified key to the specified value.\n\n**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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|key|String|The key for the property to be set.|\n|value|String|The value of the property to be set.|\n|description|String|A description of the property.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\ngs.setProperty(\"glide.foo\",\"bar\",\"foo\");\ngs.info(gs.getProperty(\"glide.foo\"));\n```\n\nOutput: bar\n\n### Scoped equivalent\n\nTo use the setProperty\\(\\) method in a scoped application, use the corresponding scoped method: [setProperty\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - setRedirect\\(Object URI\\)\n\nSets the redirect URI for this transaction, which then determines the next page the user will see.\n\n|Name|Type|Description|\n|----|----|-----------|\n|URI|Object|URI to set as the redirect|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThis example redirects the user to a particular catalog item, and passes along the current email as a parameter.\n\n```\ngs.setRedirect(\"com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=d41ce5bac611227a0167f4bf8109bf70&sysparm_user=\" \n+ current.sys_id + \"&sysparm_email=\" + current.email)\n```\n\n### Scoped equivalent\n\nTo use the setRedirect\\(\\) method in a scoped application, use the corresponding scoped method: [setRedirect\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - setReturn\\(Object URI\\)\n\nSets the return URI for this transaction. This determines what page the user will be directed to when they return from the next form.\n\n|Name|Type|Description|\n|----|----|-----------|\n|URI|Object|URI to set as the return location.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThis example ensures that the user will be returned to the current page when they are done with the next one.\n\n```\ngs.setReturn (current.getLink(true));\n```\n\n## GlideSystem - tableExists\\(String tableName\\)\n\nDetermines if a database table exists in the ServiceNow instance.\n\n|Name|Type|Description|\n|----|----|-----------|\n|tableName|String|Name of the table to check.|\n\n<table id=\"table_f3j_gw1_mt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the specified table exists in the ServiceNow instance.Possible values:\n\n-   true: Table exists\n-   false: Table does not exist\n\n</td></tr></tbody>\n</table>This example shows checking whether the incident and foo tables exist in the ServiceNow instance.\n\n```\ngs.info(\"Does the incident table exist? \" + gs.tableExists(\"incident\"));\n\ngs.info(\"Does the foo table exist? \" + gs.tableExists(\"foo\"));\n```\n\nOutput\n\n```\nDoes the incident table exist? true\nDoes the foo table exist? false\n```\n\n### Scoped equivalent\n\nTo use the tableExists\\(\\) method in a scoped application, use the corresponding scoped method: [tableExists\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - userID\\(\\)\n\nReturns the sys\\_id of the user associated with this session. Use getUserID\\(\\) instead.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the current user.|\n\nThe following example shows how to unassign all active Incident records assigned to the current user.\n\n```\nvar incidentGR = new GlideRecord('incident');\nincidentGR.addActiveQuery();\n\n// Filter results to incidents assigned to the current user\nvar currentUserSysId = gs.userID();\nincidentGR.addQuery('assigned_to', currentUserSysId);\nincidentGR.query();\n\nwhile (incidentGR.next()) {\n    incidentGR.setValue('assigned_to', 'NULL');\n    incidentGR.update();\n    gs.info(\n        'Unassigned Incident: {0}: {1}',\n        incidentGR.number.toString(),\n        incidentGR.short_description.toString()\n    );\n}\n```\n\nOutput:\n\n```\nUnassigned Incident: INC0000057: Performance problems with wifi\nUnassigned Incident: INC0009001: Unable to post content on a Wiki page\nUnassigned Incident: INC0008111: ATF : Test1\n```\n\n## GlideSystem - workflowFlush\\(Object glideRecord\\)\n\nDeletes any open scheduled job records in the Schedule \\(sys\\_trigger\\) table for the specified GlideRecord.\n\n|Name|Type|Description|\n|----|----|-----------|\n|glideRecord|Object|The GlideRecord|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n## GlideSystem - yearsAgo\\(Number years\\)\n\nGets a date and time for a certain number of years ago in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|years|Number|An integer number of years|\n\n|Type|Description|\n|----|-----------|\n|String|UTC beginning of the year that is the specified number of years ago, in the format yyyy-mm-dd hh:mm:ss.|\n\n### Scoped equivalent\n\nTo use the yearsAgo\\(Number years\\) method in a scoped application, use the corresponding scoped method: [yearsAgo\\(Number years\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n## GlideSystem - yesterday\\(\\)\n\nReturns yesterday's time \\(24 hours ago\\) in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|UTC for 24 hours ago, in the format yyyy-mm-dd hh:mm:ss|\n\n### Scoped equivalent\n\nTo use the yesterday\\(\\) method in a scoped application, use the corresponding scoped method: [yesterday\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSystemScopedAPI.md).\n\n"}}