{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1037,"path":"api-reference/server-api-reference/c_GlideSystemScopedAPI.md","title":"GlideSystem - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideSystem- Scoped\n\nThe scoped GlideSystem API provides a number of convenient methods to obtain information about the system, the current logged in user, and other system level 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## Scoped GlideSystem - addErrorMessage\\(String message\\)\n\nAdds an error message for the current session.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|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```\n\n## Scoped 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## Scoped GlideSystem - addInfoMessage\\(String message\\)\n\nAdds an info message for the current session. This method is not supported for asynchronous business rules.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|Info 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 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## Scoped 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## Scoped 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## Scoped GlideSystem - base64Encode\\(String source\\)\n\nCreates a base64 string from the specified string.\n\n|Name|Type|Description|\n|----|----|-----------|\n|source|String|String to encode.|\n\n|Type|Description|\n|----|-----------|\n|String|Encoded base64 string.|\n\nThe following code example shows how to call this method.\n\n```\nvar mac = new CertificateEncryption;\nvar key = \"sample_key\"; \nkey = gs.base64Encode(key);\nmac.generateMac(key, \"HmacSHA256\", \"sample_data\");\n```\n\n## Scoped GlideSystem - base64Decode\\(String source\\)\n\nReturns an ASCII string from the specified base64 string.\n\n|Name|Type|Description|\n|----|----|-----------|\n|source|String|A base64 encoded string.|\n\n|Type|Description|\n|----|-----------|\n|String|The decoded string.|\n\n## Scoped GlideSystem - beginningOfLastMonth\\(\\)\n\nReturns 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|UTC beginning of last month, in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped 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|Type|Description|\n|----|-----------|\n|String|UTC beginning of last week, in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped 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|Type|Description|\n|----|-----------|\n|String|UTC beginning of next month, in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped 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|Type|Description|\n|----|-----------|\n|String|The UTC beginning of next week, in the format yyyy-mm-dd hh:mm:ss.|\n\n## Scoped 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|UTC beginning of next year, in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped GlideSystem - beginningOfThisMonth\\(\\)\n\nReturns the date and time for the beginning of this 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|UTC beginning of this month, in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped GlideSystem - beginningOfThisQuarter\\(\\)\n\nReturns the date and time for the beginning of this quarter 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 beginning of this quarter, in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped 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|Type|Description|\n|----|-----------|\n|String|UTC beginning of this week, in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped 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|Type|Description|\n|----|-----------|\n|String|UTC beginning of this year, in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped 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_mhc_ljn_zv\" 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 the UTC for.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 in the 24 hour format hh:mm:ss.\n\n</td></tr></tbody>\n</table><table id=\"table_nhc_ljn_zv\" 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 GlideSystem - daysAgo\\(Number days\\)\n\nReturns the date and time for a specified number of days ago 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|UTC in the format yyyy-mm-dd hh:mm:ss|\n\n```\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 GlideSystem - daysAgoEnd\\(Number days\\)\n\nReturns the date and time for the end 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|Number|Integer number of days|\n\n|Type|Description|\n|----|-----------|\n|String|UTC end of the day in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped GlideSystem - daysAgoStart\\(Number days\\)\n\nReturns the 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 GlideSystem - debug\\(String message, Object parm1, Object parm2, Object parm3, Object parm4, Object parm5\\)\n\nWrites a debug message to the system log.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|The log message with place holders for any variable arguments.|\n|param1|Object|\\(Optional\\) First variable argument.|\n|param2|Object|\\(Optional\\) Second variable argument.|\n|param3|Object|\\(Optional\\) Third variable argument.|\n|param4|Object|\\(Optional\\) Fourth variable argument.|\n|param5|Object|\\(Optional\\) Fifth variable argument.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\ngs.debug(\"This is a debug message\");\nvar myFirstName = \"Abel\";\nvar myLastName = \"Tuter\";\ngs.debug(\"This is a debug message from {0}.{1}\", myFirstName, myLastName);\n```\n\nOutput:\n\n```\nThis is a debug message (sys.scripts extended logging)\nThis is a debug message from Abel.Tuter (sys.scripts extended logging)\n```\n\n## Scoped 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|Type|Description|\n|----|-----------|\n|String|UTC end of last month, in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped 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|Type|Description|\n|----|-----------|\n|String|UTC end of last week, in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped 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\n## Scoped 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|Type|Description|\n|----|-----------|\n|String|UTC in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped 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|Type|Description|\n|----|-----------|\n|String|UTC in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped 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|Type|Description|\n|----|-----------|\n|String|UTC in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped 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|Type|Description|\n|----|-----------|\n|String|UTC in the format yyyy-mm-dd hh:mm:ss|\n\nThis 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 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|Type|Description|\n|----|-----------|\n|String|UTC in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped 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|Type|Description|\n|----|-----------|\n|String|UTC in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped 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|Type|Description|\n|----|-----------|\n|String|UTC in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped GlideSystem - error\\(String message, Object parm1, Object parm2, Object parm3, Object parm4, Object parm5\\)\n\nWrites an error message to the system log.\n\nThis method accepts up to five variable arguments \\(varargs\\) in the message using the Java MessageFormat placeholder replacement pattern.\n\n**Note:** Variables must contain valid values for this method to provide correct output.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|The log message with place holders for any variable arguments.|\n|param1|Object|\\(Optional\\) First variable argument.|\n|param2|Object|\\(Optional\\) Second variable argument.|\n|param3|Object|\\(Optional\\) Third variable argument.|\n|param4|Object|\\(Optional\\) Fourth variable argument.|\n|param5|Object|\\(Optional\\) Fifth variable argument.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\ngs.error(\"This is an error message\");\nvar myFirstName = \"Abel\";\nvar myLastName = \"Tuter\";\ngs.error(\"This is an error message from {0}.{1}\", myFirstName, myLastName);\n```\n\nOutput:\n\n```\nThis is an error message\nThis is an error message from Abel.Tuter\n```\n\n## Scoped GlideSystem - eventQueue\\(String name, Object instance, 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|instance|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|Optional. 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 GlideSystem - eventQueueScheduled\\(String name, Object instance, String parm1, String parm2, Object expiration\\)\n\nQueues an event in the event manager.\n\nThe passed in event schedule information is stored in the Events \\[sysevent\\] table. For additional information on events, see [Events](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/build-workflows/events.md).\n\n<table id=\"table_nxv_r3k_bx\" 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\nname\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the event to queue.\n\n</td></tr><tr><td>\n\ninstance\n\n</td><td>\n\nObject/String\n\n</td><td>\n\nGlideRecord object or the sys\\_id of the record to which this event applies.\n\n</td></tr><tr><td>\n\nparm1\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. String to pass into the event script. This parameter is free-form and depends on the implementation of the event script.Default: If the **instance** parameter is a GlideRecord object, then the default is the display value for that GlideRecord \\(now\\_GR.getDisplayValue\\) otherwise it is `null`.\n\n</td></tr><tr><td>\n\nparm2\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. String to pass into the event script. This parameter is free-form and depends on the implementation of the event script. Default: `null`\n\n</td></tr><tr><td>\n\nexpiration\n\n</td><td>\n\nObject\n\n</td><td>\n\nOptional. GlideDateTime object or a date/time type element that specifies the date and time to process the event.Default: Current date/time\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThis example shows how to call the method using a GlideRecord, two parameters that are passed to the event script, and a specified time to schedule the event.\n\n```\nvar requestXml = requestBody.dataString;\nvar processTime = new GlideDateTime();\nprocessTime.addDaysLocalTime(7);\ngs.eventQueueScheduled('sn_app.user.deactivate', now_GR, requestXML, gs.getUserID(), processTime);\n```\n\nThis example shows how to call the method using a sys\\_id and the default values for the optional parameters.\n\n```\ngs.eventQueueScheduled('event.test', '0e29421383101000dada83ec37d9292d', '', '', '');\n```\n\n## Scoped GlideSystem - executeNow\\(GlideRecord job\\)\n\nExecutes a job for a scoped application.\n\nYou can only use this method on a job in the same application as the script calling this method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|job|GlideRecord|Job to run.|\n\n|Type|Description|\n|----|-----------|\n|String|Returns the sys\\_id of the scheduled job. Returns null if the job is global.|\n\n```\nscheduleImportJob: function () {\n  var jobId = '61847fe04c603300fa9bb64c2b491dac';\n  var now_GR = new GlideRecord('sysauto_script');\n  if (!now_GR.get(jobId)) {\n    throw new Error('Unable to find import job');\n  }\n  gs.executeNow(now_GR);\n}\n```\n\n## Scoped GlideSystem - generateGUID\\(\\)\n\nGenerates a GUID that can be used when a unique identifier is required.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|A 32-character hexadecimal GUID.|\n\nThe following code example shows how to call this method.\n\n```\npersonalId = gs.generateGUID();\ngs.info(personalId);\n```\n\nOutput:\n\n```\naf770511ff013100e04bfffffffffff6\n```\n\n## Scoped GlideSystem - getCallerScopeName\\(\\)\n\nGets the caller scope name; returns null if there is no caller.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The caller's scope name, or null if there is no caller.|\n\nThis example shows two script includes that are set to Accessible from all application scopes. One script include is created within app\\_scope\\_a.\n\n```\nvar Scopea = Class.create(); \n \nScopea.prototype = { \n    initialize: function() { \n    }, \n \n    callerScope: function() { \n        var scopeb = new app_scope_b.Scopeb(); \n        return scopeb.callerscope(); \n    }, \n \n    type: 'Scopea' \n}\n```\n\nOutput:\n\nThis example shows another script include created within app\\_scope\\_b.\n\n```\nvar Scopeb = Class.create(); \n \nScopeb.prototype = { \n    initialize: function() { \n        this._constructorCallerScope = gs.getCallerScopeName(); \n    }, \n \n    callerscope: function() { \n        return gs.getCallerScopeName(); \n    }, \n \n    getConstructorCallerScope: function() { \n        return this._constructorCallerScope; \n    }, \n \n    type: 'Scopeb' \n}\n```\n\nOutput:\n\nThis script can be used within scope app\\_scope\\_a to get the scope name of the caller—in this case app\\_scope\\_b.\n\n```\ngs.info(new Scopea().getCallerScopeName());\n```\n\n## Scoped GlideSystem - getCssCacheVersionString\\(\\)\n\nGets a string representing the cache version for a CSS file.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The CSS cache version.|\n\nThe following code example shows how to call this method.\n\n```\nvar verStr = gs.getCssCacheVersionString();\ngs.info(verStr);\n```\n\nOutput:\n\n```\n_d82979516f0171005be8883e6b3ee4cf&theme=\n```\n\n## Scoped GlideSystem - getCurrentApplicationId\\(\\)\n\nGets the ID of the current application as set using the Application Picker.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The current application's sys\\_id, or global in none is set.|\n\n```\nvar currentId = gs.getCurrentApplicationId();\ngs.info(currentId);\n```\n\nOutput\n\n```\n04936cb16f30b1005be8883e6b3ee4e0\n```\n\n## Scoped GlideSystem - getCurrentScopeName\\(\\)\n\nGets the name of the current scope.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The current scope name.|\n\nThe following code example shows how to call this method.\n\n```\nvar currentScope = gs.getCurrentScopeName();\ngs.info(currentScope);\n```\n\nOutput:\n\n```\ns_snc_test_scope\n```\n\n## Scoped GlideSystem - getDateFormat\\(String\\)\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## Scoped 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## Scoped GlideSystem - getErrorMessages\\(\\)\n\nReturns the error messages that were added by addErrorMessage\\(\\) for the session.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Array of Strings|Error messages associated with the session.|\n\n## Scoped GlideSystem - getEscapedMessage\\(String id, Array args\\)\n\nRetrieves the specified message from the Message \\[sys\\_ui\\_message\\] table. If the message has HTML special characters, replaces them with the corresponding HTML name codes. For example, `&` becomes `&amp;`.\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 with all special characters returned as escape sequences. If the specified message identifier does not exist for the current language, then the method returns the English version of the message with all special characters returned as escape sequences. 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_m4y_5rz_5w\" 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\nid\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\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.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|UI message with HTML special characters replaced with HTML name codes.|\n\nThis example shows the ampersand character being replaced with the equivalent ampersand HTML name code.\n\n```\nvar my_message = gs.getEscapedMessage(\"Is the summary & details accurate?\");\nalert(my_message);\n```\n\nOutput\n\n```\nIs the summary &amp; details accurate?\n```\n\nThis example shows how to replace a single variable within a message and how the &lt; and &gt; symbols in the message are transposed to the corresponding HTML name codes of &amp;lt and &amp;gt.\n\n```\n// current.action.name is \"update record\"\nvar my_message = gs.getEscapedMessage(\"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 &ltsubflow&gt can't be added twice in this subflow.\n```\n\n## Scoped GlideSystem - getMessage\\(String id, Array 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, then the method returns the translated message. If the specified message identifier does not exist for the current language, then 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_nwm_grh_1r\" 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\nid\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.\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.getMessage(\"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|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.getEscapedMessage(\"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 GlideSystem - getProperty\\(String key, Object alt\\)\n\nGets the value of a Glide property. If the property is not found, returns an alternate value.\n\n|Name|Type|Description|\n|----|----|-----------|\n|key|String|The 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|The value of the Glide property, or the alternate object defined above.|\n\nThe following code example shows how to call this method.\n\n```\nvar attachment_link = gs.getProperty('glide.servlet.uri');\ngs.info(attachment_link);\n```\n\nOutput:\n\n```\nhttps://instance.service-now.com/\n```\n\n## Scoped GlideSystem - getSession\\(\\)\n\nGets a reference to the current Glide session.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|A reference for the current session.|\n\n```\nif (!gs.hasRole(\"admin\") && !gs.hasRole(\"user_admin\") && gs.getSession().isInteractive()) {\n  current.addQuery(\"active\", \"true\");\n}\n```\n\n## Scoped GlideSystem - getSessionID\\(\\)\n\nRetrieves the GlideSession session ID.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The session ID.|\n\n```\nvar myUserObject = gs.getSessionID();\ngs.info(myUserObject);\n```\n\nOutput:\n\n```\nA0D4E5416F3F21005BE8883E6B3EE4B8\n```\n\n## Scoped GlideSystem - getSessionToken\\(\\)\n\nThis method is no longer available. Instead, use `gs.getSession().getSessionToken()`.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The session token.|\n\n## Scoped 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|The 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## Scoped GlideSystem - getTimeZoneName\\(\\)\n\nReturns the name of the time zone associated with the current user.\n\nThis method has been deprecated. Instead, use the [getTimeZoneName\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideSessionScopedAPI.md) method in the GlideSession API.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The time zone name.|\n\nThe following code example shows how to call this method.\n\n```\ngs.info(gs.getTimeZoneName());\n```\n\n## Scoped GlideSystem - getUrlOnStack\\(\\)\n\nGets the current URI for the session.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The URI.|\n\n```\ngs.info(gs.getUrlOnStack());\n```\n\n## Scoped GlideSystem - getUser\\(\\)\n\nReturns a reference to the scoped GlideUser object for the current user.\n\nSee [GlideUser - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideUserScopedAPI.md)for a list of available methods.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|GlideUser|Reference to a scoped user object.|\n\n```\nvar myUserObject = gs.getUser();\ngs.info(myUserObject);\n```\n\nOutput\n\n```\ncom.glide.script.fencing.ScopedUser@6c0645\n```\n\n## Scoped GlideSystem - getUserDisplayName\\(\\)\n\nGets the display name of the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_jtg_pwm_1r\" 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 GlideSystem - getUserID\\(\\)\n\nGets the sys\\_id of the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The 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.getUserID();\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## Scoped GlideSystem - getUserName\\(\\)\n\nReturns the user name of the current user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_u4c_mxm_1r\" 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.\n\n```\ngs.info(\"The current user name is: \" + gs.getUserName());\n```\n\nOutput:\n\n```\nThe current user name is: admin\n```\n\n## Scoped GlideSystem - hasRole\\(Object role\\)\n\nDetermines if the current user has the specified role.\n\n|Name|Type|Description|\n|----|----|-----------|\n|role|Object|The role to check.|\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the user had the role. Returns true for users with the administrator role.|\n\n```\nif (!gs.hasRole(\"admin\") && !gs.hasRole(\"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  gs.info(\"User has admin and groups admin roles\");\n}\nelse {\n  gs.info(\"User does not have both admin and groups admin roles\");\n}\n```\n\n## Scoped GlideSystem - hoursAgo\\(Number hours\\)\n\nReturns the date and time for a specified number of hours ago. Returned in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|hours|Number|Integer number of hours|\n\n|Type|Description|\n|----|-----------|\n|String|UTC in the format yyyy-mm-dd hh:mm:ss|\n\n```\nif (current.operation() == 'insert') {\n // If no due date was specified, calculate a default\n if (current.due_date == '') {\n \n  if (current.urgency == '1') {\n   // Set due date to 4 hours ahead of current time\n   current.due_date = gs.hoursAgo(-4);\n  }\n \n  if (current.urgency == '2') {\n   // Set due date to 2 days ahead of current time\n   current.due_date = gs.daysAgo(-2);\n  }\n \n  if (current.urgency == '3') {\n   // Set due date to 7 days ahead of current time\n   current.due_date = gs.daysAgo(-7);\n  }\n }\n}\n```\n\n## Scoped GlideSystem - hoursAgoEnd\\(Number hours\\)\n\nReturns the date and time for the end of the hour a specified number of hours ago. Returned in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|hours|Number|Integer number of hours|\n\n|Type|Description|\n|----|-----------|\n|String|UTC in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped GlideSystem - hoursAgoStart\\(Number hours\\)\n\nReturns the date and time for the start of the hour a specified number of hours ago. Returned in the user's session time zone as a UTC timestamp.\n\n|Name|Type|Description|\n|----|----|-----------|\n|hours|Number|Integer number of hours|\n\n|Type|Description|\n|----|-----------|\n|String|UTC in the format yyyy-mm-dd hh:mm:ss|\n\n## Scoped GlideSystem - include\\(String name\\)\n\nProvides a safe way to call a script include from the sandbox, allowing only the inclusion of trusted scripts.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Name of the script to include.|\n\n<table id=\"table_z5p_2th_1r\" 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 script include worked.Possible values:\n\n-   true: Script include worked.\n-   false: Script include failed.\n\n</td></tr></tbody>\n</table>This example gets the LDAPUtils in the current script context.\n\n```\nvar ldapServer = new GlideRecord(\"ldap_server_config\");\nldapServer.addActiveQuery();\nldapServer.query();\ngs.include(\"LDAPUtils\");\nvar ldapUtils = new LDAPUtils();\nvar errMsg = \"\";\nwhile (ldapServer.next()) {\n  var ldap = new GlideLDAP();\n  var dn = ldapServer.dn;\n  var env = ldap.setup();\n  if (env == null) {\n    errMsg = \"Failed environment setup, missing URL\";\n    gs.eventQueue(\"ldap.connection_failed\",   ldapServer, ldapServer.getDisplayValue(), errMsg);\n    gs.logError(\"LDAP server \" + ldapServer.getDisplayValue() + \" failed scheduled connection test: \" + errMsg, \"LDAP\");\n }\n}\n```\n\n## Scoped GlideSystem - info\\(String message, Object parm1, Object parm2, Object parm3, Object parm4, Object parm5\\)\n\nWrites an info message to the system log.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|The log message with place holders for any variable arguments.|\n|param1|Object|\\(Optional\\) First variable argument.|\n|param2|Object|\\(Optional\\) Second variable argument.|\n|param3|Object|\\(Optional\\) Third variable argument.|\n|param4|Object|\\(Optional\\) Fourth variable argument.|\n|param5|Object|\\(Optional\\) Fifth variable argument.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\ngs.info(\"This is an info message\");\nvar myFirstName = \"Abel\";\nvar myLastName = \"Tuter\";\ngs.info(\"This is an info message from {0}.{1}\", myFirstName, myLastName);\n```\n\nOutput:\n\n```\nThis is an info message\nThis is an info message from Abel.Tuter\n```\n\n## Scoped GlideSystem - isDebugging\\(\\)\n\nDetermines if debugging is active for a specific scope.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if either session debugging is active or the log level is set to debug for the specified scope.|\n\n```\ngs.debug(\"This is a log message\");\nvar myFirstName = \"Abel\";\nvar myLastName = \"Tuter\";\ngs.debug(\"This is a log message from {0}.{1}\", myFirstName, myLastName);\ngs.info(gs.isDebugging());\n```\n\n## Scoped GlideSystem - isInteractive\\(\\)\n\nChecks if the current session is interactive. An example of an interactive session is when a user logs in normally. An example of a non-interactive session is using a SOAP request to retrieve data.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the session is interactive.|\n\n```\nif (!gs.hasRole(\"admin\") && gs.getSession().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 GlideSystem - isLoggedIn\\(\\)\n\nDetermines if the current user is currently logged in.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the current user is logged in.|\n\n```\ngs.info(gs.isLoggedIn());\n```\n\n## Scoped GlideSystem - isMobile\\(\\)\n\nYou can determine if a request comes from a mobile device.\n\nThis method can be used in UI action conditions and business rules.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the request comes from a mobile device; otherwise, false.|\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```\nNOT submitted from mobile UI\n```\n\n## Scoped GlideSystem - minutesAgoEnd\\(Number minutes\\)\n\nReturns the date and time for the end of the minute a specified 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 126.|\n\n<table id=\"table_y1y_pny_fz\" 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.info(\"Now: \" + nowDateTime);\nvar thirtyMinutesAgoDateTime = gs.minutesAgoEnd(30);\ngs.info(\"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 GlideSystem - minutesAgoStart\\(Number minutes\\)\n\nReturns the date and time for the start of the minute a specified 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_mhk_2py_fz\" 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 GlideSystem - monthsAgo\\(Number months\\)\n\nReturns the date and time for a specified 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_wyz_xpy_fz\" 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 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_wwt_ccv_22c\" 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## Scoped GlideSystem - monthsAgoStart\\(Number months\\)\n\nReturns the date and time for the start of the month a specified 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 3 or 14.|\n\n<table id=\"table_ir4_5ry_fz\" 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 GlideSystem - nil\\(Object o\\)\n\nQueries an object and returns true if the object is null, undefined, or contains an empty string.\n\n|Name|Type|Description|\n|----|----|-----------|\n|o|Object|The object to check.|\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the object is null, undefined, or contains an empty string; otherwise, returns false.|\n\n```\nvar now_GR = new GlideRecord();\ngs.info(gs.nil(now_GR));\n```\n\nOutput\n\n```\ntrue\n```\n\n## Scoped GlideSystem - quartersAgoEnd\\(Number quarters\\)\n\nReturns the 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|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 GlideSystem - quartersAgoStart\\(Number quarters\\)\n\nReturns the 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|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 GlideSystem - setProperty\\(String key, String value, String description\\)\n\nSets the specified key to the specified value if the property is within the script's scope.\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\nThe following code example shows how to call this method.\n\n```\ngs.setProperty(\"glide.foo\",\"bar\",\"foo\");\ngs.info(gs.getProperty(\"glide.foo\"));\n```\n\nOutput:\n\n```\nbar\n```\n\n## Scoped GlideSystem - setRedirect\\(Object o\\)\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|o|Object|URI object or URI string to set as the redirect|\n\n|Type|Description|\n|----|-----------|\n|void| |\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 GlideSystem - tableExists\\(String name\\)\n\nDetermines if a database table exists.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Name of the table to check for existence.|\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the table exists. False if the table was not found.|\n\nThis 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 GlideSystem - urlEncode\\(String url\\)\n\nEncodes non-ASCII characters, unsafe ASCII characters, and spaces so the returned string can be used on the Internet. Uses UTF-8 encoding. Uses percent \\(%\\) encoding.\n\n|Name|Type|Description|\n|----|----|-----------|\n|url|String|The string to encode.|\n\n|Type|Description|\n|----|-----------|\n|String|A string with non-ASCII characters, unsafe ASCII characters, and spaces encoded.|\n\n## Scoped GlideSystem - urlDecode\\(String url\\)\n\nReplaces UTF-8 encoded characters with ASCII characters.\n\n|Name|Type|Description|\n|----|----|-----------|\n|url|String|UTF-8 percent \\(%\\) encoded characters.|\n\n|Type|Description|\n|----|-----------|\n|String|Encoded characters replaced with ASCII characters.|\n\n## Scoped GlideSystem - warn\\(String message, Object parm1, Object parm2, Object parm3, Object parm4, Object parm5\\)\n\nWrites a warning message to the system log.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|The log message with place holders for any variable arguments.|\n|param1|Object|\\(Optional\\) First variable argument.|\n|param2|Object|\\(Optional\\) Second variable argument.|\n|param3|Object|\\(Optional\\) Third variable argument.|\n|param4|Object|\\(Optional\\) Fourth variable argument.|\n|param5|Object|\\(Optional\\) Fifth variable argument.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\ngs.warn(\"This is a warning\");\nvar myFirstName = \"Abel\";\nvar myLastName = \"Tuter\";\ngs.warn(\"This is a warning from {0}.{1}\", myFirstName, myLastName);\n```\n\nOutput:\n\n```\nThis is a warning\nThis is a warning from Abel.Tuter\n```\n\n## Scoped GlideSystem - xmlToJSON\\(String xmlString\\)\n\nTakes an XML string and returns a JSON object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|xmlString|String|The XML string to be converted.|\n\n|Type|Description|\n|----|-----------|\n|Object|A JSON object representing the XML string. Null if unable to process the XML string.|\n\nThe following code example shows how to call this method.\n\n```\nvar jsonObject = gs.xmlToJSON(xmlString);\n```\n\n## Scoped GlideSystem - yearsAgo\\(Number years\\)\n\nReturns 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 GlideSystem - yesterday\\(\\)\n\nReturns yesterday's time \\(24 hours ago\\). Returned 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"}}