{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1008,"path":"api-reference/server-api-reference/c_GlideElementAPI.md","title":"GlideElement - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideElement- Global\n\nThe GlideElement API provides a number of convenient script methods for dealing with fields and their values. 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## 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_xln_v51_kt\" 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## GlideElement - canRead\\(\\)\n\nDetermines 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 equivalent\n\nTo use the canRead\\(\\) method in a scoped application, use the corresponding scoped method: [canRead\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## 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 equivalent\n\nTo use the canWrite\\(\\) method in a scoped application, use the corresponding scoped method: [canWrite\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## 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 field has changed, false otherwise.|\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 equivalent\n\nTo use the changes\\(\\) method in a scoped application, use the corresponding scoped method: [changes\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - changesFrom\\(Object value\\)\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|value|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 the parameter, false if it does not.|\n\n```\nif (theState.changesTo(resolvedState)) {\n  operation = 4; //Resolved\n}\nelse if (theState.changesTo(closedState)) {\n  operation = 11; //Resolution Accepted\n}\nelse if (theState.changesFrom(resolvedState) || theState.changesFrom(closedState)) {\n  operation = 10; //Re-open\n}\nelse {\n  operation = 6; //Update\n}\n```\n\n### Scoped equivalent\n\nTo use the changesFrom\\(\\) method in a scoped application, use the corresponding scoped method: [changesFrom\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - changesTo\\(Object value\\)\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|value|Object|An object value to check against the new value of the current field.|\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the new value matches the parameter, false if it does not.|\n\n```\nif (theState.changesTo(resolvedState)) {\n  operation = 4; //Resolved\n}\nelse if (theState.changesTo(closedState)) {\n  operation = 11; //Resolution Accepted\n}\nelse if (theState.changesFrom(resolvedState) || theState.changesFrom(closedState)) {\n  operation = 10; //Re-open\n}\nelse {\n  operation = 6; //Update\n}\n```\n\n### Scoped equivalent\n\nTo use the changesTo\\(\\) method in a scoped application, use the corresponding scoped method: [changesTo\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## 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: 98000\n\n### Scoped equivalent\n\nTo use the dateNumericValue\\(\\) method in a scoped application, use the corresponding scoped method: [dateNumericValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - debug\\(Object o\\)\n\nDebugs the object and adds debug messages using setError\\(String\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|o|Object|An object to debug.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n## 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 equivalent\n\nTo use the getAttribute\\(\\) method in a scoped application, use the corresponding scoped method: [getAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - getBaseTableName\\(\\)\n\nGets the base table of the field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Name of the base table. This name might be different from the table that the field is defined on. See [Table extension and classes](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/table-extension-and-classes.md) in the product documentation.|\n\nThe following example shows how to the base table for the Assignment Group field of an Incident record.\n\n```\nvar gr = new GlideRecord('incident');\n\n//query the Incident Records which have category as Inquiry/Help\ngr.addQuery('category','inquiry');\n\n// sort them in the order of earlier to recent created date\ngr.orderBy('sys_created_on');\ngr.query();\n\nif(gr.next()){ //If at least any one record exists matching this query\n\n  //Print the base table for the Assignment Group field\n  gs.print(\"The Base Table for the field Assignment Group is - \" + gr.assignment_group.getBaseTableName()); \n};\n```\n\nOutput:\n\n```\nThe Base Table for the field Assignment Group is - task\n```\n\n## 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 equivalent\n\nTo use the getBooleanAttribute\\(\\) method in a scoped application, use the corresponding scoped method: [getBooleanAttribute\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - getChoices\\(String dependent\\)\n\nGenerates a choice list for a field. Returns the choice values from the base table only, not from the extended table.\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|The choice values for the 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 equivalent\n\nTo use the getChoices\\(\\) method in a scoped application, use the corresponding scoped method: [getChoices\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - getChoiceValue\\(\\)\n\nGets the choice label for the current choice value.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The choice label.|\n\nThe following example shows how to get the choice label for change request records with the a priority value of Normal.\n\n```\nvar gr = new GlideRecord('change_request');\n\n//query for the change records with change type as \"Normal\"\ngr.addQuery('type','normal');\n\n// sort them in the order of recent to earlier Created Date\ngr.orderByDesc('sys_created_on'); \n\n// limit the query to 4 records\ngr.setLimit(4); \ngr.query();\n\nwhile(gr.next()){\n //Printing the choice label for those records\n gs.print(\"The label of the current priority '\"+ gr.priority+\"' for the change request - \" + gr.number + \" is - \"+ gr.priority.getChoiceValue()); \n}\n```\n\nOutput:\n\n```\nThe label of the current priority '4' for the change request - CHG0000014 is - 4 - Low\nThe label of the current priority '4' for the change request - CHG0000013 is - 4 - Low\nThe label of the current priority '4' for the change request - CHG0000012 is - 4 - Low\nThe label of the current priority '4' for the change request - CHG0000011 is - 4 - Low\n```\n\n### Scoped equivalent\n\nTo use the getChoiceValue\\(\\) method in a scoped application, use the corresponding scoped method: [getChoiceValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - getDebugCount\\(\\)\n\nGets the number of debug messages logged by debug\\(\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The number of debug messages.|\n\n## GlideElement - getDependent\\(\\)\n\nReturns the field \\(element\\) that a specified field is dependent on.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Name of the field on which the current field depends. Null if no dependencies.|\n\nThe following example shows how to find the parent field of the Configuration Item field using the getDependent\\(\\) method.\n\n```\nvar inc_gr = new GlideRecord('incident');\ninc_gr.get('985f53d82fab301032e8808cf699b6e8'); // Get a particular Incident\n\nvar field_element = inc_gr.getElement('cmdb_ci'); // Get the Configuration Item element\nvar dependent_field = field_element.getDependent(); // Read the dependent field\ngs.info(\"Dependent field: \" + dependent_field);\nif(dependent_field)\n  {\n    var dependent_field_value = inc_gr.getValue(dependent_field);  \n    if(!dependent_field_value)\n      {\n        var base_table = field_element.getRefRecord(); // Retrieve the reference record\n        var dependent_field_value = base_table.getValue(dependent_field); // Read the parent field value\n      }\n    inc_gr.setValue(dependent_field, dependent_field_value); // Update the parent field on the Incident\n    inc_gr.update();\n  }\n```\n\nOutput:\n\n```\ncompany\n```\n\n## GlideElement - getDependentTable\\(\\)\n\nReturns the name of the table that a field is dependent on.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Name of the table if a field has a dependent table; null otherwise.|\n\nThe following example shows how to determine if a field named **model\\_id** has a dependent table.\n\n```\nvar gr = new GlideRecord('cmdb_ci_hardware');\ngr.setLimit(1);\ngr.query();\n\nif (gr.next()) {\n    var field_element = gr.getElement('model_id'); // Get the model_id field element\n    var dependent_table = field_element.getDependentTable(); // Get the table that drives filtering\n\n    gs.info(\"Field: \" + field_element.getLabel());\n    gs.info(\"Dependent table: \" + dependent_table); // cmdb_model_category\n\n    if (dependent_table) {\n        // Use the dependent table to query what's controlling the filter\n        var dep_gr = new GlideRecord(dependent_table);\n        if (dep_gr.get(gr.getValue('model_category'))) {\n            gs.info(\"Controlling record: \" + dep_gr.getDisplayValue());\n            gs.info(\"Only models belonging to category '\" + dep_gr.getDisplayValue() + \"' are valid for this CI\");\n        }\n    }\n}\n```\n\nOutput:\n\n```\nField: Model ID\nDependent table: null\n```\n\n## GlideElement - getDisplayValue\\(Number maxChar\\)\n\nReturns the formatted display value of the field.\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\n|Name|Type|Description|\n|----|----|-----------|\n|maxChar|Number|Optional. Maximum number of characters to return.|\n\n|Type|Description|\n|----|-----------|\n|String|Display value of the field.|\n\n```\nvar fields = current.getFields();\nfor (var i = 0; i < fields.size(); i++) { \n  var field = fields.get(i);\n  var name = field.getName(); \n  var value = field.getDisplayValue(); \n  gs.print(i + \". \" + name + \"=\" + value); \n}\n```\n\n### Scoped equivalent\n\nTo use the getDisplayValue\\(\\) method in a scoped application, use the corresponding scoped method: [getDisplayValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - getDisplayValueExt\\(Number maxChar, String nullSub\\)\n\nReturns the formatted display value of a field, or a specified substitute value if the display value is null or empty.\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\n<table id=\"table_q5w_5hc_kt\" 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\nmaxChar\n\n</td><td>\n\nNumber\n\n</td><td>\n\nOptional. Maximum number of characters to be returned.Default: All\n\n</td></tr><tr><td>\n\nnullSub\n\n</td><td>\n\nString\n\n</td><td>\n\nValue to return if the display value is null or empty.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Formatted display value of the field, or the specified substitute value.|\n\nThe following example shows how to display the two most recent active records in the Incident \\[incident\\] table.\n\n```\nvar gr = new GlideRecord('incident');\ngr.addQuery('active', true);      // get the active records\ngr.orderByDesc('sys_updated_on'); // sort the records from most recent to oldest updated date\ngr.setLimit(2);                   // limit the query to 2 records\ngr.query();\n\nwhile(gr.next()){ // Printing the Display Value of the Configuration Item field. \n  // If the Display Value is Null/Empty, then it will be substituted with Default value \"I with Null/Empty Display Value\"\n  gs.info(\"The Display Value of the Configuration Item for the incident - \"+ gr.number+ \" is \" + gr.cmdb_ci.getDisplayValueExt(40, \" CI with Null/Empty Display Value\"));\n}\n```\n\nOutput:\n\n```\nThe Display Value of the Configuration Item for the incident - INC0007001 is  CI with Null/Empty Display Value\nThe Display Value of the Configuration Item for the incident - INC0000069 is NYC RAC\n```\n\n## 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 equivalent\n\nTo use the getDisplayValueLang\\(\\) method in a scoped application, use the corresponding scoped method: [getDisplayValueLang\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - getDynamicAttribute\\(\\)\n\nReturns a dynamic attribute definition for this GlideElement.\n\nDynamic attributes have a defined data type and a sys\\_id. For more details on dynamic attributes, see [Dynamic schema](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/dynamic-schema.md).\n\nSee also:\n\n-   [GlideDynamicAttribute - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicAttributeAPI.md)\n-   [GlideDynamicAttributeStore - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicAttStoreAPI.md)\n-   [GlideDynamicNamespace - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicNamespaceAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|IDynamicAttribute|Object describing the attribute that the GlideElement represents.|\n\nThe following example shows how to get values of the make attribute from the u\\_inc\\_dynamic\\_schema dynamic attribute store column on the incident table.\n\n```\nvar gr_Inc = new GlideRecord('incident');\ngr_Inc.query();\nif(gr_Inc.next()) {\n    var attr = gr_Inc.getDynamicAttribute('inc_dynamic_schema->make');\n    gs.info(attr.getValue());\n}\n```\n\n## GlideElement - getDynamicNamespace\\(\\)\n\nReturns a dynamic namespace object that is configured for the GlideElement.\n\nDynamic attributes have a defined data type and a sys\\_id. For more details on dynamic attributes, see [Dynamic schema](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/dynamic-schema.md).\n\nSee also:\n\n-   [GlideDynamicAttribute - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicAttributeAPI.md)\n-   [GlideDynamicAttributeStore - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicAttStoreAPI.md)\n-   [GlideDynamicNamespace - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicNamespaceAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|IDynamicNamespace|Object describing the dynamic namespace.|\n\nThe following example shows how to retrieve the namespace object configured for the inc\\_dynamic\\_schema dynamic attribute store column on the incident table.\n\n```\nvar gr_Inc = new GlideRecord('incident');\ngr_Inc.query();\nif (gr_Inc.next()) {\n    var ge_Make = gr_Inc.getElement('inc_dynamic_schema->make');\n    var namespace = ge_Make.getDynamicNamespace();\n \n    gs.info(\"toString:    \" + namespace);\n    gs.info(\"name:        \" + namespace.getName());\n    gs.info(\"isActive:    \" + namespace.isActive());\n    gs.info(\"isTransient: \" + namespace.isTransient());\n}\n```\n\nOutput:\n\n```\ntoString:    incident/inc_dynamic_schema\nname:        incident/inc_dynamic_schema\nisActive:    true\nisTransient: false\n```\n\n## GlideElement - getDynamicNamespaceName\\(\\)\n\nGets the name of the dynamic namespace configured for the GlideElement.\n\nDynamic attributes have a defined data type and a sys\\_id. For more details on dynamic attributes, see [Dynamic schema](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/dynamic-schema.md).\n\nSee also:\n\n-   [GlideDynamicAttribute - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicAttributeAPI.md)\n-   [GlideDynamicAttributeStore - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicAttStoreAPI.md)\n-   [GlideDynamicNamespace - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideDynamicNamespaceAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Name of the dynamic namespace.|\n\nThe following example shows how to return the dynamic attribute namespace name.\n\n```\n// Gets the name of the namespace from the inc_dynamic_schema dynamic_attribute_store column on the incident table\n \nvar gr_Inc = new GlideRecord('incident');\ngr_Inc.query();\nif (gr_Inc.next()) {\n    var ge_Make = gr_Inc.getElement('inc_dynamic_schema->make');\n    gs.info(ge_Make.getDynamicNamespaceName());\n}\n```\n\nOutput:\n\n```\nnumber,short_description,active\n```\n\n## GlideElement - getED\\(\\)\n\nReturns an element descriptor, which provides information about specific fields, rather than the data inside of those fields.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|ElementDescriptor|The field's element descriptor.|\n\nThis example gets the fields and field descriptors for the current record.\n\n```\nvar fields = current.getFields();\nfor (i=0; i<fields.size(); i++) { \n  var field = fields.get(i);\n  var descriptor = field.getED(); \n  gs.print(\"type=\" + descriptor.getType() + \n    \" internalType=\" + descriptor.getInternalType()); \n}\n```\n\n### Scoped equivalent\n\nTo use the getED\\(\\) method in a scoped application, use the corresponding scoped method: [getED\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - getElementValue\\(String value\\)\n\nReturns the value for the specified element.\n\n|Name|Type|Description|\n|----|----|-----------|\n|value|String|Element whose value you want returned.|\n\n|Type|Description|\n|----|-----------|\n|String|Value of the element.|\n\n```\nvar fields = current.getFields();\nfor (var i = 0; i < fields.size(); i++) {\n  var field = fields.get(i);\n  var name = field.getName();\n\n  // Returns the unformatted value of the element\n  var value = field.getElementValue(name);\n  var disValue = field.getDisplayValue();\n  gs.print(i + \". \" + name + \" = \" + value + ' display value = ' + disValue);\n}\n```\n\nOutput\n\n```\n1. cmdb_ci = 109562a3c611227500a7b7ff98cc0dc7 display value = Storage Area Network 001\n2. impact = 2 display value = 2 - Medium\n```\n\n## GlideElement - getError\\(\\)\n\nReturns any error message associated with the specified element.\n\nUse the [setError\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementAPI.md) method to set an error on a specific field \\(element\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Error message currently set for the specified element.|\n\nThis example shows how to set an error on the short\\_description element and then read the error back.\n\n```\nvar incidentGR = new GlideRecord('incident');\nincidentGR.setLimit(1);\nincidentGR.query();\nif (incidentGR.next()) {\n    incidentGR.short_description.setError('The description is too short.');\n    gs.info(incidentGR.short_description.getError()); // 'The description is too short.'\n}\n```\n\nOutput:\n\n```\nThe description is too short.\n```\n\nThis example shows how to use **getError\\(\\)** in a function call.\n\n```\n// Before query business rule (order = 100)\n(function executeRule(current, previous /*null when async*/) {\n    var shortDescription = current.getValue('short_description');\n    if (shortDescription.length < 10) {\n        current.short_description.setError('The description is too short.');\n        current.setAbortAction(true);\n    }\n})(current, previous);\n\n// Before query business rule (order = 200)\n(function executeRule(current, previous /*null when async*/) {\n    var shortDescriptionErrMsg = current.short_description.getError();\n    if (shortDescriptionErrMsg) {\n        // Some error was set in one of the previous business rules.\n    }\n})(current, previous);\n```\n\n## GlideElement - getEscapedValue\\(\\)\n\nGets the escaped value for the current element.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The escaped value of the current element.|\n\nThe following example shows how to use the getEscapedValue\\(\\) method to display the contents of an Incident short description field with escape characters.\n\n```\n/*** Overview - Update incident short description with escape characters and printing ***/\nvar inc = new GlideRecord('incident');\ninc.query();\ninc.next();\ninc.short_description = 'Can\\'t log into SAP from my laptop today'; \ninc.update();\ngs.info(\"Short Description: \"+inc.getElement('short_description').toString()); //without escape characters\ngs.info(\"Escaped Short Description: \"+inc.getElement('short_description').getEscapedValue()); // with escape characters\n```\n\nOutput:\n\n```\nShort Description: Can't log into SAP from my laptop today\nEscaped Short Description: Can\\'t log into SAP from my laptop today\n```\n\n## GlideElement - getFieldStyle\\(\\)\n\nGets the CSS style for the field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The CSS style for the field.|\n\n```\nvar fields = current.getFields();\nfor (var i = 0; i < fields.size(); i++) { \n  var field = fields.get(i);\n  var css_style = field.getFieldStyle();  \n  gs.print(\"CSS style\" + \"=\" + css_style); \n}\n```\n\n## GlideElement - getGlideObject\\(\\)\n\nRetrieves the platform object associated with the field's value.\n\nFor a use case, see [Modify GlideDateTime field values](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/r_UsefulFieldScripts.md).\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 equivalent\n\nTo use the getGlideObject\\(\\) method in a scoped application, use the corresponding scoped method: [getGlideObject\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - getGlideRecord\\(\\)\n\nGets a glide record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|GlideRecord|A glide record object.|\n\n```\nvar grInc = new GlideRecord('incident');\ngrInc.get('sys_id','ef43c6d40a0a0b5700c77f9bf387afe3');\ngs.info(\"Initial grInc - \" + grInc.getDisplayValue());\n\nvar caller = grInc.getElement(\"caller_id\");\ndoit(caller);\n\nfunction doit(caller) {\n  var now_GR = caller.getGlideRecord();\n  gs.info(\"doit gr is - \" + now_GR.getDisplayValue());\n}\n```\n\nOutput\n\n```\n*** Script: Initial grInc - INC0000050\n*** Script: doit gr is - INC0000050\n```\n\n## 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\nThe following example shows how to get the HTML content of a meeting note.\n\n```\n/*\n  getHTMLValueExt() This Function is used to get HTML Value of a field. It accepts 2 Parameters\n\na. maxChar- Number - The maximum number of characters to return.\nb. nullSub - String - The value to return if the HTML value is null or empty.\n\n*/\n\n\n// get a cab meeting record by its sys_id\nvar gr = new GlideRecord('cab_meeting');\ngr.addQuery('sys_id','7777777b6d2a20100sys70id534330f6');\ngr.query();\n\nif(gr.next()){\n  var substituteString = 'Meeting Notes Unavailable';\n  var maxLength = 50;\n  gs.print(gr.meeting_notes.getHTMLValueExt(maxLength, substituteString));\n}\n```\n\n### Scoped equivalent\n\nTo use the getHTMLValue\\(\\) method in a scoped application, use the corresponding scoped method: [getHTMLValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - getHTMLValueExt\\(Number maxChar, String nullSub\\)\n\nReturns the HTML value of a field, or a specified substitute value if the HTML value is null or empty.\n\n|Name|Type|Description|\n|----|----|-----------|\n|maxChar|Number|The maximum number of characters to return.|\n|nullSub|String|The value to return if the HTML value is null or empty.|\n\n|Type|Description|\n|----|-----------|\n|String|The HTML value or the specified substitute value.|\n\nThe following example shows how to get the HTML content of a meeting note.\n\n```\n// get a cab meeting record by its sys_id\nvar gr = new GlideRecord('cab_meeting');\ngr.addQuery('sys_id','7777777b6d2a20100sys70id534330f6');\ngr.query();\n\nif(gr.next()){\n  var substituteString = 'Meeting Notes Unavailable';\n  var maxLength = 50;\n  gs.print(gr.meeting_notes.getHTMLValueExt(maxLength, substituteString));\n}\n```\n\nOutput if the meeting note for the record selected is not empty:\n\n```\n<p>Meeting note content.</p>\n```\n\n## 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_av3_wmc_kt\" 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.print(na[i]);\n```\n\n### Scoped equivalent\n\nTo use the getJournalEntry\\(\\) method in a scoped application, use the corresponding scoped method: [getJournalEntry\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - getLabel\\(\\)\n\nReturns the object's label.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Object's label|\n\n```\nvar now_GR = new GlideRecord(\"sc_req_item\");\nnow_GR.addQuery(\"request\", current.sysapproval);\nnow_GR.query();\nwhile(now_GR.next()) {\n    var 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 equivalent\n\nTo use the getLabel\\(\\) method in a scoped application, use the corresponding scoped method: [getLabel\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## 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 equivalent\n\nTo use the getLabelLang\\(\\) method in a scoped application, use the corresponding scoped method: [getLabelLang\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## 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 equivalent\n\nTo use the getName\\(\\) method in a scoped application, use the corresponding scoped method: [getName\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## 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.notNullQuery('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.print( grUSER.getValue('name') ); \n\n} \n```\n\n### Scoped equivalent\n\nTo use the getRefRecord\\(\\) method in a scoped application, use the corresponding scoped method: [getRefRecord\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - getStyle\\(\\)\n\nGet the CSS style for the value.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The CSS style for the value.|\n\n```\n// Get string of style field from Field Style record\nvar cssStyle = now_GR.state.getStyle();\n```\n\n## 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 equivalent\n\nTo use the getTableName\\(\\) method in a scoped application, use the corresponding scoped method: [getTableName\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - getTextAreaDisplayValue\\(\\)\n\nRetrieves the display value for the associated field and escapes the HTML.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Escaped [display value](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/c_DisplayValues.md) HTML for the associated field.|\n\nThe following example retrieves the display value of a KB article.\n\n```\nvar grh = new GlideRecord('kb_knowledge');\ngrh.get('c85cd2519f77230088aebde8132e70c2');  // Knowledge record sys_id\nvar t = grh.text.getTextAreaDisplayValue(); // Text is HTML type field\nvar d = GlideXMLUtil.parseHTML(t); // Parse the HTML\nvar b = d.getDocumentElement().getTextContent().trim();\ngs.info(b);\n```\n\nOutput:\n\n```\nThis article explains how to use automatic replies in Outlook 2010 for Exchange accounts.\n\nSetting Up Automatic Replies\n\nClick the \nFile tab.\nClick \nAutomatic Replies.\nSelect \nSend automatic replies.\nIf desired, select the \nOnly send during this time range check box to schedule when your out of office replies are active. If you do not specify a start and end time, auto-replies will be sent until you select the\n Do not send automatic replies check box.\nOn the \nInside My Organization tab, type the response that you want to send to colleagues while you are out of the office.\nOn the \nOutside My Organization tab, select the \nAuto-reply to people outside my organization check box, and then type the response that you want to send while you are out of the office. Select whether you want replies sent to \nMy contacts only or to \nAnyone outside my organization who sends you messages.\n\nNOTE:\nIf you select \nMy Contacts only in step 6, replies will be sent \nonly to contacts that exist in your Contacts folder.\n\n\n\nUsing Rules With Automatic Replies\nIt is also possible to use rules to manage your messages while you are out of office. For example, you can create rules to automatically move or copy messages to other folders, to delete messages, to send custom replies, and so on.\n\nClick the \nFile tab.\nClick \nAutomatic Replies.\nClick \nRules, and then click \nAdd Rule.\nUnder \nWhen a message arrives that meets the following conditions, specify the conditions that the message must meet for the rule to be applied. If you want to specify more conditions, click \nAdvanced, enter or select the options that you want, and then click \nOK.\nIf you want to specify that this rule must be applied last, select the \nDo not process subsequent rules check box.\nUnder \nPerform these actions, select the actions that you want. You can select more than one action.\nClick \nOK three times.\n\nNOTES:\n\nAutomatic Replies rules can also be edited by following the above procedure.\nTo turn Automatic Replies rules on or off, in the Automatic Reply Rules dialog box, select or clear the check box of the rule that you want to turn on or off.\n\n```\n\n## GlideElement - getValue\\(\\)\n\nReturns the value of the field in the database.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The value of the field.|\n\nThe following example retrieves the value of a specified field in the 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 equivalent\n\nTo use the getValue\\(\\) method in a scoped application, use the corresponding scoped method: [Scoped GlideElement - getValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - getXHTMLValue\\(\\)\n\nRetrieves the XHTML value of a field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The XHTML value|\n\n## GlideElement - getXMLValue\\(\\)\n\nGets the XML value of a field as a string.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The XML value|\n\n## GlideElement - hasAttribute\\(String attributeName\\)\n\nDetermines if a field has a specified attribute.\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<table id=\"table_sbf_zrc_kt\" 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 a field has the specified attribute.Valid values:\n\n-   true: The field has the specified attribute.\n-   false: The field does not have the specified attribute.\n\n</td></tr></tbody>\n</table>The following example shows how to get fields from the User \\[sys\\_user\\] table with the **edge\\_encryption\\_enabled** attribute.\n\n```\nvar fields = new GlideRecord('sys_user');\n\nfields.query();\n\nvar userFields = fields.getFields();\n\nfor (var num = 0; num < userFields.size(); num++) {\n    var ed = userFields.get(num).getED();\n\n    if (ed.hasAttribute(\"edge_encryption_enabled\")) {\n        gs.info(userFields.get(num).getName());\n    }\n}\n```\n\nOutput:\n\n```\n*** Script: hashed_user_id\n*** Script: federated_id\n```\n\n## GlideElement - hasRightsTo\\(String operationName\\)\n\nDetermines if the user has the right to perform a particular operation.\n\n|Name|Type|Description|\n|----|----|-----------|\n|operationName|String|Name of the operation to check for|\n\n<table id=\"table_tpp_msc_kt\" 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\nTrue if the user has permission to perform the operation, false otherwise.Flag that indicates whether a user has permission to perform an operation.\n\n Valid values:\n\n-   true: User has permissions.\n-   false: User does not have permissions.\n\n</td></tr></tbody>\n</table>The following example shows how to determine if a user has rights to read a specific table.\n\n```\n// Pass table name and userId to check if user has read access against given table name\ncheckAccess('incident', 'adela.cervantsz');\n\nfunction checkAccess(tableName, userID) {\n\n    var inc = new GlideRecordSecure(tableName);\n    inc.get('$[sys_id]');\n\n    var secureManager = GlideSecurityManager.get();\n\n    //fetch a different user, using user_name field on the target user record\n    var userObj = gs.getUser().getUserByID(userID); \n    secureManager.setUser(userObj);\n\n    var access = 'record/incident/read';\n\n    //check if user has right to access\n    var canRead = secureManager.hasRightsTo(access, inc); \n    gs.info('canRead: ' + canRead);\n}\n```\n\nOutput:\n\n```\ncanRead: false\n```\n\n## GlideElement - hasValue\\(\\)\n\nDetermines if the field has a value.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the field has a value, false otherwise.|\n\n## GlideElement - nil\\(\\)\n\nDetermines whether the field is null.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the field is null or an empty string, false otherwise.|\n\n```\nif (current.start_date.changes() || current.end_date.changes() || current.assigned_to.changes()) { \n  if (!current.start_date.nil() && !current.end_date.nil() && !current.assigned_to.nil()) {\n gs.eventQueue(\"change.calendar.notify\", current, current.assigned_to, previous.assigned_to);\n \n}\n```\n\n### Scoped equivalent\n\nTo use the nil\\(\\) method in a scoped application, use the corresponding scoped method: [nil\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - setDateNumericValue\\(Number milliseconds\\)\n\nSets the duration field to a 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|milliseconds|Number|Number of milliseconds spanned by the duration.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar inc = new GlideRecord('incident');\ninc.get('17c90efb13418700cc36b1422244b05d');\nvar timems = inc.calendar_duration.dateNumericValue();\ntimems = timems + 11*1000; \ninc.calendar_duration.setDateNumericValue(timems)\ngs.info(inc.calendar_duration.getValue());\n```\n\nOutput:\n\n```\n1970-01-01 00:01:38\n```\n\n### Scoped equivalent\n\nTo use the setDateNumericValue\\(\\) method in a scoped application, use the corresponding scoped method: [setDateNumericValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - setDisplayValue\\(Object displayValue\\)\n\nSets the display value of the field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|displayValue|Object|Value to be displayed.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n### Scoped equivalent\n\nTo use the setDisplayValue\\(\\) method in a scoped application, use the corresponding scoped method: [setDisplayValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - setError\\(String errorMessage\\)\n\nAdds an error message to the associated field.\n\nYou can retrieve the error message using the [getError\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementAPI.md) method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|errorMessage|String|The error message.|\n\n|Type|Description|\n|----|-----------|\n|None| |\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.setAbortAction(true);\n    current.u_date1.setError('start must be before end');\n  }\n}\n```\n\n### Scoped equivalent\n\nTo use the setError\\(\\) method in a scoped application, use the corresponding scoped method: [setError\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - setInitialValue\\(Object value\\)\n\nSets the initial value of a field.\n\nThis method had been deprecated. Use [GlideElement - setValue\\(Object value\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementAPI.md) for this functionality.\n\n|Name|Type|Description|\n|----|----|-----------|\n|value|Object|Initial value for the field.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n## GlideElement - setJournalEntry\\(String entry, String userName\\)\n\nAdds a journal entry and author as a work note or comment field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|entry|String|Content of the journal entry.|\n|userName|String|Optional. The user to attribute the journal entry to.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows how to add a work note and its author to a record.\n\n```\nvar now_GR = new GlideRecord(\"incident\");\n\nnow_GR.addQuery(\"sys_id\", \"<sys_id_value>\");\nnow_GR.query();\n\nif(now_GR.next()){\n  now_GR.work_notes.setJournalEntry(\"Content of the journal entry.\", \"abel.tuter\");  \n  now_GR.update();\n}\n```\n\n## 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|The value the field is to be set 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 equivalent\n\nTo use the setValue\\(\\) method in a scoped application, use the corresponding scoped method: [setValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n## GlideElement - toString\\(\\)\n\nConverts the field's value to a string.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The field's value as a string.|\n\n```\ndoit();\n \nfunction doit() { \n \n  var now_GR = new GlideRecord('sys_user');\n  now_GR.query();\n  while (now_GR.next()) {\n  if ((now_GR().length != now_GR.first_name.toString().trim().length) || (now_GR.last_name.toString().length \n         != now_GR.last_name.toString().trim().length)) {\n      now_GR.first_name = now_GR.first_name.toString().trim();\n      now_GR.last_name = now_GR.last_name.toString().trim();\n      now_GR.autoSysFields(false);\n      now_GR.update();\n    }\n  }\n \n}\n```\n\n### Scoped equivalent\n\nTo use the toString\\(\\) method in a scoped application, use the corresponding scoped method: [toString\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md).\n\n"}}