{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1010,"path":"api-reference/server-api-reference/c_GlideElementScopedAPI.md","title":"GlideElement - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideElement- Scoped\n\nThe scoped GlideElement API provides a number of convenient script methods for dealing with fields and their values. Scoped GlideElement methods are available for the fields of the current glide record.\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 GlideElement - canCreate\\(\\)\n\nDetermines if the user's role permits the creation of new entries in the associated field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_iq2_gmp_fz\" 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 permissions to create new entries in the associated field.Possible values:\n\n-   true: User can create new entries.\n-   false: User cannot create new entries.\n\n</td></tr></tbody>\n</table>The following example shows how to determine if the user has permissions to create entries for the three most recent records in the Problem \\[problem\\] table.\n\n```\nvar gr = new GlideRecord('problem');\n\n// Get records in new state in Problem Table\ngr.addQuery('state','101');\n\n// Sort records in order of recent to earlier Created Date\ngr.orderByDesc('sys_created_on');\n\n// Limit the query to three records\ngr.setLimit(3); \ngr.query();\n\nwhile(gr.next()){\n  if(gr.short_description.canCreate()){ ///check to see if the current user is allowed to create the record\n  gs.info(\"I can create new records for the field Problem statement for - \" + gr.number);\n  }\n}\n```\n\nOutput:\n\n```\nI can create new records for the field Problem statement for - PRB0000004\nI can create new records for the field Problem statement for - PRB0001000\nI can create new records for the field Problem statement for - PRB0001001\n```\n\n### Scoped equivalent\n\nTo use the canCreate\\(\\) method in a scoped application, use the corresponding scoped method: [canCreate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## Scoped GlideElement - canRead\\(\\)\n\nIndicates whether the user's role permits them to read the associated GlideRecord.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the field can be read, false otherwise.|\n\nThe following example shows how to get a list of active Incident records with a readable Short Description field.\n\n```\nvar grIncident = new GlideRecord('incident');\ngrIncident.addEncodedQuery(\"active=true\"); //Query the Incident table for active incidents\ngrIncident.orderByDesc('number');\ngrIncident.setLimit(3); // limit to three results for example\ngrIncident.query();\n\nwhile (grIncident.next()) {\n    if (grIncident.short_description.canRead()) { //check to see if the current user is allowed to read the record\n        gs.info('You have permission to read the short description of: ' + grIncident.number + ' ' + grIncident.short_description);\n    }\n}\n```\n\nOutput:\n\n```\n*** Script: You have permission to read the short description of: INC0009009 Unable to access the shared folder.\n*** Script: You have permission to read the short description of: INC0009005 Email server is down.\n*** Script: You have permission to read the short description of: INC0009001 Unable to post content on a Wiki page\n```\n\n## Scoped GlideElement - canWrite\\(\\)\n\nDetermines whether the user's role permits them to write to the associated GlideRecord.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the user can write to the field, false otherwise.|\n\nThe following example shows how to get a list of active Incident records with a writeable Short Description field.\n\n```\nvar grIncident = new GlideRecord('incident');\ngrIncident.addEncodedQuery(\"active=true\"); //Query the Incident table for active incidents\ngrIncident.orderByDesc('number');\ngrIncident.setLimit(3); // limit to three results for example\ngrIncident.query();\n\nwhile (grIncident.next()) {\n    if (grIncident.short_description.canWrite()) { //check to see if the current user is allowed to write to the record\n        gs.info('You have permission to write to the short description of: ' + grIncident.number + ' ' + grIncident.short_description);\n    }\n}\n```\n\nOutput:\n\n```\n*** Script: You have permission to write to the short description of: INC0009009 Unable to access the shared folder.\n*** Script: You have permission to write to the short description of: INC0009005 Email server is down.\n*** Script: You have permission to write to the short description of: INC0009001 Unable to post content on a Wiki page\n```\n\n## Scoped GlideElement - changes\\(\\)\n\nDetermines if the current field has been modified. This functionality is available for all available data types, except Journal fields.\n\n**Note:** The changes\\(\\) method is not supported within ACL scripts.\n\n**Note:** If the GlideRecord on which you are performing this method has only been initialized and read, and has not been written, the underlying before-and-after values are the same. In this case, the method returns \"false\", as there has been no change to the data store.\n\n-   **Business rule execution**\n\n    The ServiceNow AI Platform invokes business rules \\(**BEFORE** or **AFTER**\\) before resetting the internal previous values for columns \\(GlideElement objects\\) to the current values.\n\n    This sequence enables the following actions:\n\n    -   Triggering an **AFTER** business rule on &lt;column&gt;.changes conditions.\n    -   Accessing the previous GlideRecord object in the script section.\n    Even in **AFTER** business rules, `current.<field>.changes()` returns `true` because the internal previous values haven’t been reset yet. The condition `current.<field>.value != previous.<field>.value` also returns `true`.\n\n    Previous values are only reset after the following activities:\n\n    -   The database update is complete.\n    -   All **AFTER** business rules have been processed.\n    Inside an AFTER business rule, the changes\\(\\) method still returns `true` if the field value was modified, even though the rule executes after the update.\n\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the fields have been changed, false if the field has not.|\n\nThe following example from a business rule shows how to create an event in the EventQueue if the value of the **assigned\\_to** field changes. For a comprehensive example, see [Sample scripts from the change events business rule](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_ChangeEventsSampleScripts.md).\n\n```\nif (!current.assigned_to.nil() && current.assigned_to.changes()) {\n  gs.eventQueue('incident.assigned', current, current.assigned_to.getDisplayValue(), previous.assigned_to.getDisplayValue());\n}\n```\n\n## Scoped GlideElement - changesFrom\\(Object o\\)\n\nDetermines if the previous value of the current field matches the specified object.\n\n**Note:** If the GlideRecord on which you are performing this method has only been initialized and read, and has not been written, the underlying before-and-after values are the same. In this case, the method returns \"false\", as there has been no change to the data store.\n\n|Name|Type|Description|\n|----|----|-----------|\n|o|Object|An object value to check against the previous value of the current field.|\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the previous value matches, false if it does not.|\n\n```\n// The following example shows that in a business rule, if \"active\" field is changed from true, \n// insert a event in the EventQueue.\nif (current.active.changesFrom(true)) {\n  gs.eventQueue(\"incident.inactive\", current, current.incident_state, previous.incident_state);\n}\n```\n\n## Scoped GlideElement - changesTo\\(Object o\\)\n\nDetermines if the new value of a field, after a change, matches the specified object.\n\n**Note:** The changesTo\\(\\) method is not supported within ACL scripts.\n\n**Note:** If the GlideRecord on which you are performing this method has only been initialized and read, and has not been written, the underlying before-and-after values are the same. In this case, the method returns \"false\", as there has been no change to the data store.\n\n|Name|Type|Description|\n|----|----|-----------|\n|o|Object|An object value to check against the new value of the current field.|\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the previous value matches, false if it does not.|\n\n```\n// The following example shows that in a business rule, if \"active\" field is changed to false, \n// insert a event in the EventQueue.\nif (current.active.changesTo(false)) {\n  gs.eventQueue(\"incident.inactive\", current, current.incident_state, previous.incident_state);\n}\n```\n\n## Scoped GlideElement - dateNumericValue\\(\\)\n\nReturns the number of milliseconds since January 1, 1970, 00:00:00 GMT for a duration field. Does not require the creation of a GlideDateTime object because the duration field is already a GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|Number of milliseconds since January 1, 1970, 00:00:00 GMT.|\n\n```\nvar inc = new GlideRecord('incident');\ninc.get('17c90efb13418700cc36b1422244b05d');\ngs.info(inc.calendar_duration.dateNumericValue());\n```\n\nOutput:\n\n```\n98000\n```\n\n## Scoped GlideElement - getAttribute\\(String attributeName\\)\n\nReturns the value of the specified attribute from the dictionary.\n\nFor Boolean attributes, you can use the getBooleanAttribute\\(\\) method to return the value as a Boolean instead of a string.\n\n|Name|Type|Description|\n|----|----|-----------|\n|attributeName|String|Name of the attribute. The attribute name is listed in the Dictionary Entries \\[sys\\_dictionary\\] table.|\n\n|Type|Description|\n|----|-----------|\n|String|Value of the specified attribute.|\n\nThe following example shows how to get the value of the **tree\\_picker** attribute in the **location** column of the User \\[sys\\_user\\] table as a string.\n\n```\nvar now_GR = new GlideRecord('sys_user');\nnow_GR.query(\"user_name\",\"admin\");\n\nif (now_GR.next()) {\n   gs.info(\"The value of the tree_picker attribute in the location column is \" + now_GR.location.getAttribute(\"tree_picker\"));\n}\n```\n\nOutput:\n\n```\nThe value of the tree_picker attribute in the location column is true\n```\n\n## Scoped GlideElement - getBooleanAttribute\\(String attributeName\\)\n\nReturns a specified Boolean-type attribute from the dictionary as a Boolean value.\n\nTo return the attribute value as a string, use the getAttribute\\(\\) method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|attributeName|String|Name of the attribute. The attribute name is listed in the Dictionary Entries \\[sys\\_dictionary\\] table.|\n\n|Type|Description|\n|----|-----------|\n|Boolean|Specifies the value of the attribute as Boolean true or false.|\n\nThe following example shows how to get Boolean values of the **ignore\\_filter\\_on\\_new** attribute for two fields.\n\n```\nvar inc = new GlideRecord('incident');\ninc.query();\n\nif (inc.next())\n {\n   // opened_by field has attribute \"ignore_filter_on_new = true\"\n   gs.info(inc.opened_by.getBooleanAttribute(\"ignore_filter_on_new\"));\n\n  // short_description field does not have attribute ignore_filter_on_new\n   gs.info(inc.short_description.getBooleanAttribute(\"ignore_filter_on_new\"));\n }\n```\n\nOutput:\n\n```\ntrue\nfalse\n```\n\n## Scoped GlideElement - getChoices\\(String dependent\\)\n\nReturns the choice list for a specified field.\n\nThe field for which to return the choice list is specified in the method call. For example: `var choices = glideRecord.urgency.getChoices();`. For information on choice list field types and their associated capabilities, see [Choice list field type](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/c_ChoiceLists.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|dependent|String|Optional. Field within the associated record on which the choice list field depends.|\n\n|Type|Description|\n|----|-----------|\n|Array|List of possible values for the choice list, which are the values in the Choice \\[sys\\_choice\\] table. If the **dependent** parameter is passed, the return results reflect only those choices available for the specified dependent field.|\n\n```\nvar glideRecord = new GlideRecord('incident'); \nglideRecord.query('priority','1'); \nglideRecord.next(); \n \n// urgency has choice list: 1 - High, 2 - Medium, 3 - Low, with value: 1, 2, 3\nvar choices = glideRecord.urgency.getChoices();\n```\n\n## Scoped GlideElement - getChoiceValue\\(\\)\n\nReturns the choice label for the current choice.\n\nA choice has a value \\(number\\) and a label \\(string\\). This method returns the label.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The selected choice's label.|\n\n```\nvar glideRecord = new GlideRecord('incident'); \nglideRecord.query('priority','1'); \nglideRecord.next(); \n \n// urgency has choice list: 1 - High, 2 - Medium, 3 - Low, with value: 1, 2, 3\nvar choiceLabel = glideRecord.urgency.getChoiceValue(); \ngs.info(choiceLabel);\n```\n\nOutput:\n\n```\n1 - High\n```\n\n## Scoped GlideElement - getDecryptedValue\\(\\)\n\nReturns the clear text value for Password \\(2 way encrypted\\) fields in scoped applications.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The clear text password.|\n\n```\nvar tablename = 'x_scoped_app_table'\nvar CI = new GlideRecord(tablename);  \nCI.addQuery('number', '0001002'); \nCI.query(); \nCI.next(); \n\nvar password = CI.password_field\nvar decrypted = password.getDecryptedValue(); \ngs.info(decrypted);\n```\n\nOutput:\n\n```\nx_scoped_app: cleartextpassword\n```\n\n## Scoped GlideElement - getDisplayValue\\(Number maxCharacters\\)\n\nReturns the formatted display value of a specified field from an associated GlideRecord object.\n\nDisplay values are manipulated based on the actual value in the database and user or system settings and preferences.\n\nThe display value that is returned is dependent on the field type.\n\n-   Choice fields: The database value may be a number, but the display value will be more descriptive.\n-   Date fields: The database value is in UTC format, while the display value is based on the user's time zone.\n-   Encrypted text: The database value is encrypted, while the displayed value is unencrypted based on the user's encryption context.\n-   Reference fields: The database value is sys\\_id, but the display value is a display field of the referenced record.\n\nFor more information on display values, see [Display values](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/c_DisplayValues.md).\n\n<table id=\"table_vy2_525_jq\" 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\nmaxCharacters\n\n</td><td>\n\nNumber\n\n</td><td>\n\nOptional. Maximum characters desired.Default: All\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Display value of the specified field.|\n\nThe following example shows how to retrieve the display value of the priority field in an incident record.\n\n```\nvar glideRecord = new GlideRecord('incident');\nglideRecord.query('priority','1');\nglideRecord.next();\ngs.info(glideRecord.priority.getDisplayValue());\n```\n\nOutput:\n\n```\n1 - Critical\n```\n\nThe following example shows how to retrieve both the display value and internal value of specified fields in the incident database.\n\n```\nvar now_GR = new GlideRecord('incident');\nnow_GR.get('9c573169c611228700193229fff72400'); //INC0000001\ngs.info('Display Values:');\ngs.info('Opened at ' + now_GR.opened_at.getDisplayValue());\ngs.info('Opened by ' + now_GR.opened_by.getDisplayValue());\ngs.info('Priority ' + now_GR.priority.getDisplayValue());\ngs.info('Values:');\ngs.info('Opened at ' + now_GR.opened_at.getValue());\ngs.info('Opened by ' + now_GR.opened_by.getValue());\ngs.info('Priority ' + now_GR.priority.getValue());\n\n```\n\nOutput:\n\n```\nDisplay Values:\nOpened at 2022-02-01 15:09:51\nOpened by Joe Employee\nPriority 1 - Critical\nValues:\nOpened at 2022-02-01 23:09:51\nOpened by 681ccaf9c0a8016400b98a06818d57c7\nPriority 1\n\n```\n\n## Scoped GlideElement - getDisplayValueLang\\(String language\\)\n\nGets the display value of the field in the language passed as a parameter.\n\nThe result is only applicable to translatable field types such as **Choice**, **Translated Field**, and **Translated Text**. For other field types, the result defaults to [getDisplayValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\nYou must have the corresponding language plugin to retrieve a translated value. For information, see [Activate a language](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/t_ActivateALanguage.md).\n\nSee also [Scoped GlideElement - getLabelLang\\(String language\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|language|String|Language tag conforming with IETF BCP-47.|\n\n|Type|Description|\n|----|-----------|\n|String|Display value of the field in the language passed. If a translation isn't available, the method retrieves a value translated in the language of the current user. If a translation isn’t available, the result defaults to English.|\n\nThe following example shows how to get the original text and German-translated text from the **Accept** \\(UI View\\) title field.\n\n```\nvar uiView = new GlideRecord(\"sys_ui_view\");\nuiView.get(\"fa776f6d97700100f309124eda2975bc\");\n\ngs.info(\"getDisplayValue: \" + uiView.getElement(\"title\").getDisplayValue());\ngs.info(\"getDisplayValueLang: \" + uiView.getElement(\"title\").getDisplayValueLang(\"de\"));\n```\n\nOutput:\n\n```\ngetDisplayValue: Accept\ngetDisplayValueLang: Akzeptieren\n```\n\n## Scoped GlideElement - getED\\(\\)\n\nReturns the field's element descriptor.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|GlideElementDescriptor|The field's element descriptor.|\n\n```\nvar grInc = new GlideRecord('incident');\ngrInc.query('priority', '1');\n \nvar field = grInc.getElement('priority');\nvar ed = field.getED();\n```\n\n## Scoped GlideElement - getGlideObject\\(\\)\n\nRetrieves the platform object associated with the field's value.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Object|A platform object corresponding to the field's data type, such as GlideDateTime. You can use this object for type-specific operations on the value. For example, date arithmetic, formatting, and timezone conversions that are not available when accessing the field value as a plain string.|\n\nThe following example shows how to calculate the duration between the opened date and Service Level Agreement \\(SLA\\) due date of an incident record.\n\n```\n// Query an incident record with both opened_at and sla_due populated\nvar incGr = new GlideRecord('incident');\nincGr.addQuery('opened_at', '!=', '');\nincGr.addQuery('sla_due', '!=', '');\nincGr.setLimit(1);\nincGr.query();\n\nif (incGr.next()) {\n    gs.info(\"Incident: \" + incGr.getValue('number'));\n    gs.info(\"Opened at: \" + incGr.getValue('opened_at'));\n    gs.info(\"SLA due: \" + incGr.getValue('sla_due'));\n\n    var duration = calcDateDelta(incGr.opened_at, incGr.sla_due);\n    if (duration) {\n        gs.info(\"Duration in seconds: \" + duration.getNumericValue() / 1000);\n        gs.info(\"Duration display value: \" + duration.getDisplayValue());\n    }\n}\n\nfunction calcDateDelta(start, end) {\n    var realStart = start.getGlideObject();\n    var realEnd = end.getGlideObject();\n\n    // Use GlideDuration to calculate the difference between two GlideDateTime objects\n    var startMS = realStart.getNumericValue();\n    var endMS = realEnd.getNumericValue();\n    var deltaMS = endMS - startMS;\n\n    // Create a GlideDuration from the millisecond difference\n    var duration = new GlideDuration(deltaMS);\n    return duration;\n}\n```\n\nOutput:\n\n```\nIncident: INC0000031\nOpened at: 2025-03-06 00:18:03\nSLA due: 2025-03-06 08:18:03\nDuration in seconds: 28800\nDuration display value: 8 Hours\n```\n\n## Scoped GlideElement - getGlobalDisplayValue\\(\\)\n\nReturns the phone number in international format.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Phone number in international format.|\n\nThe following example shows how to get the phone number of a walk-up location. This example requires the Walk-up Experience plugin.\n\n```\n// Passing walkup location name and closed phone number in parameters\nsetWalkupLocPhone('Santa Clara Tech Lounge','phone_number');\n\nfunction setWalkupLocPhone(locName, field) {\n  var walkupLoc = new GlideRecord('wu_location_queue');\n  walkupLoc.addQuery('name',locName);\n  walkupLoc.query();\n  walkupLoc.next();\n\n  // Returns the phone number of walk-up location queue in international format\n  gs.info(walkupLoc[field].getGlobalDisplayValue());\n}\n```\n\nOutput:\n\n```\n+91 98124 56789\n```\n\n## Scoped GlideElement - getHTMLValue\\(Number maxChars\\)\n\nReturns the HTML value of a field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|maxChars|Number|Optional. Maximum number of characters to return.|\n\n|Type|Description|\n|----|-----------|\n|String|HTML value for the field.|\n\n```\nvar inccause = new GlideRecord(\"incident\");\ninccause.short_description = current.short_description;\ninccause.comments = current.comments.getHTMLValue();\ninccause.insert();\n```\n\n## Scoped GlideElement - getJournalEntry\\(Number mostRecent\\)\n\nReturns either the most recent journal entry or all journal entries.\n\n|Name|Type|Description|\n|----|----|-----------|\n|mostRecent|Number|If 1, returns the most recent entry. If -1, returns all journal entries.|\n\n<table id=\"table_mpt_2wp_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\nFor the most recent entry, returns a string that contains the field label, timestamp, and user display name of the journal entry.\n\n For all journal entries, returns the same information for all journal entries ever entered as a single string with each entry delimited by \"\\\\n\\\\n\".\n\n</td></tr></tbody>\n</table>```\n//gets all journal entries as a string where each entry is delimited by '\\n\\n'\nvar notes = current.work_notes.getJournalEntry(-1); \n//stores each entry into an array of strings\nvar na = notes.split(\"\\n\\n\");  \n                      \nfor (var i = 0; i < na.length; i++)                 \n  gs.info(na[i]);\n```\n\n## Scoped GlideElement - getLabel\\(\\)\n\nReturns the object label.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Object label|\n\n```\nvar now_GR = new GlideRecord(\"sc_req_item\");\nnow_GR.addQuery(\"request\", current.sysapproval);\nnow_GR.query();\nwhile(now_GR.next()) {\nvar nicePrice = now_GR.price.toString();\n    if (nicePrice != ) {\n        nicePrice = parseFloat(nicePrice);\n        nicePrice = nicePrice.toFixed(2);\n    }\n    template.print(now_GR.number + \":  \" + now_GR.quantity + \" X \" + now_GR.cat_item.getDisplayValue() + \" at $\" + nicePrice + \" each \\n\");\n    template.print(\"    Options:\\n\");\n    var variables = now_GR.variables.getElements();    \n    for (var key in variables) {\n      var now_V = variables[key];\n      if(now_V.getQuestion().getLabel() != ) {\n         template.space(4);\n         template.print('     ' +  now_V.getQuestion().getLabel() + \" = \" + now_V.getDisplayValue() + \"\\n\");  \n      }\n    }\n}\n```\n\n## Scoped GlideElement - getLabelLang\\(String language\\)\n\nGets the label value of the field in the language passed as a parameter.\n\nYou must have the corresponding language plugin to retrieve a translated value. For information, see [Activate a language](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/t_ActivateALanguage.md).\n\nSee also:\n\n-   [getDisplayValueLang\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md)\n-   [getLabel\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|language|String|Language tag conforming with IETF BCP-47.|\n\n|Type|Description|\n|----|-----------|\n|String|Value of the field label in the language passed. If a translation isn't available, the method retrieves a value translated in the language of the current user. If a translation isn’t available, the result defaults to English.|\n\nThe following example shows how to get the original label text and its German translation of the **Accept** \\(UI View\\) title.\n\n```\nvar uiView = new GlideRecord(\"sys_ui_view\");\nuiView.get(\"fa776f6d97700100f309124eda2975bc\");\n\ngs.info(\"getLabel: \" + uiView.getElement(\"title\").getLabel());\ngs.info(\"getLabelLang: \" + uiView.getElement(\"title\").getLabelLang(\"de\"));\n```\n\nOutput:\n\n```\ngetLabel: Title\ngetLabelLang: Titel\n```\n\n## Scoped GlideElement - getName\\(\\)\n\nReturns the name of the field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Field name.|\n\nThe following example shows how to get the name and other values for each field in a sys\\_user record.\n\n```\nvar userRec = new GlideRecord(\"sys_user\"); // GlideRecord to sys_user table\n\nuserRec.get(\"5137153cc611227c000bbd1bd8cd2005\"); // Sys Id of user: Fred Luddy\n\nvar fields = userRec.getFields();\n\nfor (var i = 0; i < fields.size(); i++) {\n\n    var field = fields.get(i);\n    var name = field.getName(); // Name of the field\n    var label = field.getLabel(); // Label of the field\n    var value = field.getDisplayValue(); // Value of the field\n\n    gs.info((Number(i) + 1) + \".\\n\" + \"Field Label: \" + label + \"\\n\" + \"Field Name: \" + name + \"\\n\" + \"Field Value: \" + value);\n\n};\n```\n\nOutput. Results include 62 fields and have been truncated with ellipsis points \\(…\\) to save space.\n\n```\n*** Script: 1.\nField Label: Country code\nField Name: country\nField Value: \n*** Script: 2.\nField Label: Calendar integration\nField Name: calendar_integration\nField Value: Outlook\n...\n*** Script: 47.\nField Label: First name\nField Name: first_name\nField Value: Fred\n...\n*** Script: 54.\nField Label: Last name\nField Name: last_name\nField Value: Luddy\n...\n```\n\n## Scoped GlideElement - getReferenceTable\\(\\)\n\nGets the table name for a reference element.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Table name of the reference.|\n\n```\nvar grINC = new GlideRecord('incident');\ngrINC.query('number','INC0010041'); // record assignment group assigned to \"CAB Approval\"\nif (grINC.next()) { \n  // Get the table name \n  var tableName = grINC.assignment_group.getReferenceTable();\n  gs.info( tableName ); \n}\n```\n\n## Scoped GlideElement - getRefRecord\\(\\)\n\nReturns a GlideRecord object for a given reference element.\n\nFor calculated fields, this method fetches the referenced record and runs a calculation on a scripted default value.\n\n**Warning:** If the reference element does not contain a value, it returns an empty GlideRecord object, not a NULL object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|GlideRecord|A GlideRecord object|\n\n```\n\nvar grINC = new GlideRecord('incident'); \ngrINC.addNotNullQuery('caller_id'); \ngrINC.query(); \nif (grINC.next()) { \n\n// Get a GlideRecord object for the referenced sys_user record \nvar grUSER = grINC.caller_id.getRefRecord(); \nif (grUSER.isValidRecord()) \n  gs.info(grUSER.getValue('name')); \n\n} \n```\n\n## Scoped GlideElement - getTableName\\(\\)\n\nReturns the name of the table that contains the field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Name of the table that contains the field that is called on. The returned value might be different from the table class that the record is in. For more information, see [Table extension and classes](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/table-extension-and-classes.md).|\n\n```\nif (current.approver.getTableName() == \"sysapproval_approver\") {\n    if (current.approver == email.from_sys_id) {\n        current.comments = \"reply from: \" + email.from + \"\\n\\n\" + email.body_text;\n\n        // if it's been cancelled, it's cancelled.\n        var doit = true;\n        if (current.state == 'cancelled')\n            doit = false;\n\n        if (email.body.state != undefined)\n            current.state = email.body.state;\n\n        if (doit)\n            current.update();\n    } else {\n        gs.log(\"Approval for task \" + current.sysapproval.getDisplayValue() +\n            \" rejected because user sending email \" + email.from +\n            \" does not match the approver \" + current.approver.getDisplayValue());\n    }\n}\n```\n\n## Scoped GlideElement - getValue\\(\\)\n\nReturns the value of a specified field from a GlideRecord object.\n\nThis method returns the internal value of the associated database field. To return the [display value](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/c_DisplayValues.md) of the field, use the [getDisplayValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md) method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Value of the field.|\n\nThe following example shows how to retrieve both the display value and internal value of specified fields in the incident database.\n\n```\nvar now_GR = new GlideRecord('incident');\nnow_GR.get('9c573169c611228700193229fff72400'); //INC0000001\ngs.info('Display Values:');\ngs.info('Opened at ' + now_GR.opened_at.getDisplayValue());\ngs.info('Opened by ' + now_GR.opened_by.getDisplayValue());\ngs.info('Priority ' + now_GR.priority.getDisplayValue());\ngs.info('Values:');\ngs.info('Opened at ' + now_GR.opened_at.getValue());\ngs.info('Opened by ' + now_GR.opened_by.getValue());\ngs.info('Priority ' + now_GR.priority.getValue());\n\n```\n\nOutput:\n\n```\nDisplay Values:\nOpened at 2022-02-01 15:09:51\nOpened by Joe Employee\nPriority 1 - Critical\nValues:\nOpened at 2022-02-01 23:09:51\nOpened by 681ccaf9c0a8016400b98a06818d57c7\nPriority 1\n\n```\n\n## Scoped GlideElement - nil\\(\\)\n\nDetermines if a field is null.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_bdf_zfr_2r\" 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 field is null.Possible values:\n\n-   true: Field is null.\n-   false: Field is not null.\n\n</td></tr></tbody>\n</table>```\nvar glideRecord = new GlideRecord('incident'); \nglideRecord.query('priority','1'); \nglideRecord.next(); \ngs.info(glideRecord.state.nil());\n```\n\nOutput:\n\n```\nfalse\n```\n\n## Scoped GlideElement - setDateNumericValue\\(Number milliseconds\\)\n\nSets the value of a date/time element to the specified number of milliseconds since January 1, 1970 00:00:00 GMT.\n\nWhen called, setDateNumericValue\\(\\) automatically creates the necessary GlideDateTime/GlideDate/GlideDuration object, and then sets the element to the specified value.\n\n**Note:** Before calling this method, the element must already exist by querying an existing record or by using the now\\_GR.initialize\\(\\) method to initialize a new record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|milliseconds|Number|Number of milliseconds since 1/1/1970|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar now_GR = new GlideRecord(\"incident\");\nnow_GR.initialize();\nnow_GR.opened_at.setDateNumericValue(10000);\n```\n\n## Scoped GlideElement - setDisplayValue\\(Object value\\)\n\nSets the display value of the field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|value|Object|The value to set for the field.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar glideRecord = new GlideRecord('incident'); \nglideRecord.query('priority','1'); \nglideRecord.next();\n \n//change the urgency to 3 \nglideRecord.urgency.setDisplayValue('3 - Low');\ngs.info(glideRecord.urgency);\n```\n\n## Scoped GlideElement - setError\\(String errorMessage\\)\n\nAdds an error message to the associated field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|errorMessage|String|The error message.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows how to set an error message on Priority 1 incidents with empty short descriptions.\n\n```\nvar now_GR = new GlideRecord('incident');\nnow_GR.addQuery('priority', '1');\nnow_GR.query();\n\nif (now_GR.next()) {\n    var shortDesc = now_GR.short_description.toString();\n\n    if (!shortDesc || shortDesc.trim() === '') {\n        now_GR.short_description.setError(\n            'A short description is required for all Priority 1 incidents. Please provide a brief summary of the issue.'\n        );\n    }\n}\n```\n\n## Scoped GlideElement - setPhoneNumber\\(Object phoneNumber, Boolean strict\\)\n\nSets the field to the specified phone number.\n\nThis method is only available on a phone number GlideElement.\n\n|Name|Type|Description|\n|----|----|-----------|\n|phoneNumber|Object|The phone number to set. This can be in either the international or local format.|\n|strict|Boolean|When true, specifies that the number specified must match the correct format. When false, the system attempts to correct an improperly formatted phone number.|\n\n<table id=\"table_fxy_3m2_bx\" 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 phone number value was set.Possible values:\n\n -   true: Value was set.\n-   false: Value was not set.\n\n</td></tr></tbody>\n</table>The following example shows how to set the phone number of a walk-up location. This example requires the Walk-up Experience plugin.\n\n```\nsetWalkupLocPhone('Santa Clara Tech Lounge','+91 9812456789'); \n\nfunction setWalkupLocPhone(locName, phoneNumber) {\n  var walkupLoc = new GlideRecord('wu_location_queue');\n  walkupLoc.addQuery('name', locName);\n  walkupLoc.query();\n  walkupLoc.next();\n  \n  // Set phone number of walk-up location\n  var isPhoneNumberSet = walkupLoc.phone_number.setPhoneNumber(phoneNumber, true);\n  walkupLoc.update();\n  gs.info('Phone Number: ' + walkupLoc.phone_number);\n  gs.info('Is phone number specified match the correct format: ' + isPhoneNumberSet);\n}\n```\n\nOutput:\n\n```\nPhone Number: +919812456789\nIs phone number specified match the correct format: true\n```\n\n## Scoped GlideElement - setValue\\(Object value\\)\n\nSets the value of a field.\n\n**Note:** Before calling this method, the element must already exist by querying an existing record or by using the now\\_GR.initialize\\(\\) method to initialize a new record.\n\n-   **Not for authentication with password2 fields**\n\n    The setValue\\(\\) method passes password2 data as clear text, which results in an error about expecting encrypted data. Additionally, using the setValue\\(\\) method for password2 fields exposes data that should be encrypted.\n\n    For password2 authentication, use the setDisplayValue\\(\\) method instead.\n\n    See also:\n\n    -   [Deprecate GlideEncrypter usage of 3DES for password2 fields](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/password2-3des-deprecation.md)\n    -   [Alternatives to GlideEncrypter usage in knowledge base article KB1320986](https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1320986)\n    -   [Password2 encryption with the Key Management Framework \\(KMF\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/password-2way-encrypted-fields.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|value|Object|Object value to set the field to.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nSet the value passing a string.\n\n```\nvar glideRecord = new GlideRecord('incident');\nglideRecord.query('priority','1');\nglideRecord.next();\nglideRecord.short_description.setValue('Network failure');\n```\n\nSet the value passing an object.\n\n```\nvar now_GR  = new GlideRecord('student');\nnow_GR.initialize();\nnow_GR.setValue('first_name', 'Joe');\nnow_GR.setValue('last_name', 'Smith');\nnow_GR.insert();\n```\n\n## Scoped GlideElement - toString\\(\\)\n\nConverts the value of a GlideRecord field to a string.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Value as a string.|\n\n```\nvar glideRecord = new GlideRecord('incident');\nglideRecord.query('priority','1');\nglideRecord.next();\ngs.info(glideRecord.opened_at.toString());\n```\n\nOutput:\n\n```\n2019-08-31 23:09:51\n```\n\n"}}