{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1023,"path":"api-reference/server-api-reference/c_GlideRecordScopedAPI.md","title":"GlideRecord - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideRecord- Scoped\n\nThe scoped GlideRecord API is used for database operations.\n\nThe GlideRecord API is the primary means of interfacing with the database on the server-side code. A GlideRecord is an object that contains records from a single table. Use the API to instantiate a GlideRecord object and add query parameters, filters, limits, and ordering.\n\nSee the [GlideRecord](https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_scripting_utah_scripting_in_servicenow/app_store_learnv2_scripting_utah_server_side_scripting/app_store_learnv2_scripting_utah_gliderecord) article for details on building and running queries.\n\nFor information on a class that performs the same functions as GlideRecord and enforces ACLs, see [Using GlideRecordSecure](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/p_GlideServerAPIs.md).\n\nAlways test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert\\(\\), update\\(\\), deleteRecord\\(\\), or deleteMultiple\\(\\) method on bad query results can result in data loss.\n\nYou can set the **glide.invalid\\_query.returns\\_no\\_rows** system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when **glide.invalid\\_query.returns\\_no\\_rows** is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term\\(s\\) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see [Available system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_AvailableSystemProperties.md).\n\n## Retrieve values from records\n\nIn most cases, don’t use dot-walking to get values from a record. Dot-walking retrieves the entire object instead of the field value. Retrieving the object uses more storage and might cause undesirable results when used in arrays or in Service Portal.\n\nInstead of retrieving the entire object, you can use one of the following methods to copy the field values:\n\n-   [getValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [getDisplayValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n\nIf dot-walking through a GlideElement object is necessary, use the toString\\(\\) method to retrieve values. For example, you might need the current caller's manager sys\\_id to set another reference field. The following example shows how to get the string value instead of the entire object:\n\n```\nvar mgr = current.caller_id.manager.toString();\n```\n\nSee also:\n\n-   [GlideAggregate](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideAggregateScopedAPI.md)\n-   [GlideElement](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md)\n-   [GlideQuery](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideQueryGlobalAPI.md)\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 GlideRecord - addActiveQuery\\(\\)\n\nAdds a filter to return active records.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|GlideQueryCondition|Filter to return active records.|\n\n```\nvar inc = new GlideRecord('incident');\ninc.addActiveQuery();\ninc.query();\n```\n\n## Scoped GlideRecord - addEncodedQuery\\(String query, Boolean enforceFieldACL\\)\n\nAdds an encoded query to other queries that may have been set.\n\nAlways test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert\\(\\), update\\(\\), deleteRecord\\(\\), or deleteMultiple\\(\\) method on bad query results can result in data loss.\n\nYou can set the **glide.invalid\\_query.returns\\_no\\_rows** system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when **glide.invalid\\_query.returns\\_no\\_rows** is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term\\(s\\) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see [Available system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_AvailableSystemProperties.md).\n\n**Note:** To enforce query access based on the user, use[addUserEncodedQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.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\nquery\n\n</td><td>\n\nString\n\n</td><td>\n\nAn [encoded query string](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).\n\n</td></tr><tr><td>\n\nenforceFieldACL\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nOptional. Flag that indicates whether to enforce field ACL \\(Access Control List\\) rules.Valid values:\n\n-   true: Enforce field ACLs.\n-   false: Don't enforce field ACLs.\n\nDefault: false\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar queryString = \"priority=1^ORpriority=2\";\nvar now_GR = new GlideRecord('incident');\nnow_GR.addEncodedQuery(queryString);\nnow_GR.query();\nwhile (now_GR.next()) {\n  gs.addInfoMessage(now_GR.getValue('number'));\n}\n```\n\n## Scoped GlideRecord - addFunction\\(Object function\\)\n\nApplies a pre-defined GlideDBFunctionBuilder object to a record.\n\nUse the GlideDBFunctionBuilder scoped class to define a function. After the function is defined, use the addFunction\\(Object function\\) method to apply the function to a record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|function|Object|GlideDBFunctionBuilder object that defines a SQL operation.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar functionBuilder = new GlideDBFunctionBuilder();\nvar myAddingFunction = functionBuilder.add();\nmyAddingFunction = functionBuilder.field('order');\nmyAddingFunction = functionBuilder.field('priority');\nmyAddingFunction = functionBuilder.build();\n\n// Query incidents in which order + priority is less than 5 and display that added value\nvar now_GR = new GlideRecord('incident');\nnow_GR.addFunction(myAddingFunction);\nnow_GR.addQuery(myAddingFunction, '<', 5);\nnow_GR.query();\nwhile(now_GR.next())\n  gs.info(now_GR.getValue(myAddingFunction));\n```\n\nOutput:\n\n```\n1\n4\n3\n1\n1\n2\n1\n```\n\n## Scoped GlideRecord – addJoinQuery\\(String joinTable, String primaryField, String joinTableField\\)\n\nAdds a filter to return records based on a relationship in a table related to the current GlideRecord.\n\nYou can use this method to find all the users that are in the database group via the Group Member \\[sys\\_user\\_grmember\\] table, or to find all problems that have an assigned incident via the incident.problem\\_id relationship.\n\nThis is not a true database join; rather, addJoinQuery\\(\\) adds a subquery. So, while the result set is limited based on the join, the only fields that you have access to are those on the base table \\(those which are in the table with which the GlideRecord was initialized.\\)\n\nAlways test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert\\(\\), update\\(\\), deleteRecord\\(\\), or deleteMultiple\\(\\) method on bad query results can result in data loss.\n\nYou can set the **glide.invalid\\_query.returns\\_no\\_rows** system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when **glide.invalid\\_query.returns\\_no\\_rows** is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term\\(s\\) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see [Available system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_AvailableSystemProperties.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\njoinTable\n\n</td><td>\n\nString\n\n</td><td>\n\nName of table to use in the join, such as **'incident'**.\n\n</td></tr><tr><td>\n\nprimaryField\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Name of the field in the GlideRecord to use to join the field specified in the **joinTableField** parameter.Default: sys\\_id\n\n</td></tr><tr><td>\n\njoinTableField\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Name of the field in the table specified in **joinTable** to use to join the tables.Default: First field in the table specified in **joinTable** that is a reference field to the current GlideRecord table.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|GlideQueryCondition|Filter that lists records where the relationships match.|\n\nFind problems that have an incident attached. This example returns problems that have associated incidents. However, it won't pull values from the incidents that are returned as a part of the query.\n\n```\nvar prob = new GlideRecord('problem');\nprob.addJoinQuery('incident');\nprob.query();\n```\n\nFind inactive problems with associated incidents.\n\n```\n// Look for Problem records that have associated Incident records\nvar now_GR = new GlideRecord('problem');\nvar grSQ = now_GR.addJoinQuery('incident');\n \n// Where the Problem records are \"active=false\"\nnow_GR.addQuery('active', 'false');\n \n// And the Incident records are \"active=true\"\ngrSQ.addCondition('active', 'true');\n \n// Query\nnow_GR.query();\n \n// Iterate and output results\nwhile (now_GR.next()) {\ngs.info(now_GR.getValue('number'));\n}\n```\n\nFind problems that have incidents associated where the incident **caller\\_id** field value matches that of the problem **opened\\_by** field.\n\n```\nvar now_GR = new GlideRecord('problem'); \n        now_GR.addJoinQuery('incident', 'opened_by', 'caller_id'); \n        now_GR.query();\n```\n\n## Scoped GlideRecord - addNotNullQuery\\(String fieldName\\)\n\nA filter that specifies records where the value of the field passed in the parameter is not null.\n\nAlways test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert\\(\\), update\\(\\), deleteRecord\\(\\), or deleteMultiple\\(\\) method on bad query results can result in data loss.\n\nYou can set the **glide.invalid\\_query.returns\\_no\\_rows** system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when **glide.invalid\\_query.returns\\_no\\_rows** is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term\\(s\\) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see [Available system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_AvailableSystemProperties.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|fieldName|String|The name of the field to be checked.|\n\n|Type|Description|\n|----|-----------|\n|GlideQueryCondition|A filter that specifies records where the value of the field passed in the parameter is not null.|\n\n```\nvar target = new GlideRecord('incident'); \ntarget.addNotNullQuery('short_description');\ntarget.query();   // Issue the query to the database to get all records where short_description is not null\nwhile (target.next()) {   \n     // add code here to process the incident record\n}\n```\n\n## Scoped GlideRecord - addNullQuery\\(String fieldName\\)\n\nAdds a filter to return records where the value of the specified field is null.\n\nAlways test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert\\(\\), update\\(\\), deleteRecord\\(\\), or deleteMultiple\\(\\) method on bad query results can result in data loss.\n\nYou can set the **glide.invalid\\_query.returns\\_no\\_rows** system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when **glide.invalid\\_query.returns\\_no\\_rows** is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term\\(s\\) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see [Available system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_AvailableSystemProperties.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|fieldName|String|The name of the field to be checked.|\n\n|Type|Description|\n|----|-----------|\n|GlideQueryCondition|The query condition added to the GlideRecord.|\n\n```\nvar target = new GlideRecord('incident'); \ntarget.addNullQuery('short_description');\ntarget.query();   // Issue the query to the database to get all records where short_description is null\nwhile (target.next()) {   \n   // add code here to process the incident record\n}\n```\n\n## Scoped GlideRecord - addQuery\\(String name, Object value\\)\n\nBuild a search query and return the rows that match the request.\n\nIf you are familiar with SQL, this method is similar to the \"where\" clause. One or more addQuery\\(\\) calls can be made in a single query; in this case the queries are AND'ed. If any of the query statements need to be OR'ed, use the GlideQueryCondition method [addOrCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md).\n\n**Note:** To enforce query access based on the user, use[addUserQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md).\n\nWhen addQuery\\(\\) is called with only two parameters, table name and comparison value, such as `myObj.addQuery('category','Hardware');`, the operator is assumed to be \"equal to\".\n\nAlways test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert\\(\\), update\\(\\), deleteRecord\\(\\), or deleteMultiple\\(\\) method on bad query results can result in data loss.\n\nYou can set the **glide.invalid\\_query.returns\\_no\\_rows** system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when **glide.invalid\\_query.returns\\_no\\_rows** is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term\\(s\\) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see [Available system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_AvailableSystemProperties.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\nname\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the table field to query, or one of the following reserved names:-   123TEXTQUERY321: Adds a string search term to the query. Specify the string you want to match as the value. Use this option to return records with field values containing the search string. This option searches against all fields in the table, which must be configured for indexing and search. For more information about configuring tables for indexing and search, see [Configure a single table for indexing and searching](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/configure-single-table-for-indexing.md).\n-   123TEXTINDEXGROUP321: Adds a text index group to the query. Specify the name of the text index group from the Text Index Groups \\[ts\\_index\\_group\\] table you want to query as the value. Use this option to return search results from one of the tables in a text index group, with result relevancy scores normalized using that text index group's settings. For more information about configuring text index groups, see [Configure multiple tables for indexing and searching](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/index-multiple-tables.md).\n\n**Note:** For more details on the use of the reserved names, see [Querying tables in script](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/c_UsingGlideRecordToQueryTables.md).\n\n</td></tr><tr><td>\n\nvalue\n\n</td><td>\n\nObject\n\n</td><td>\n\nValue on which to query \\(not case-sensitive\\).\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|GlideQueryCondition|Query condition added to the GlideRecord.|\n\nThis code example shows how to query the active records in the incident table and then set them all to inactive.\n\n```\nvar rec = new GlideRecord('incident');\nrec.addQuery('active', true);\nrec.query();\nwhile (rec.next()) {\n  rec.setValue('active', false);\n  rec.update();\n}\n```\n\nThis code example adds a query for records that match \"email server\" in the kb\\_knowledge table, with search result relevancy values computed using settings from the portal text index group.\n\n```\nvar now_GR = new GlideRecord(\"kb_knowledge);\nnow_GR.addQuery(\"123TEXTQUERY321\", \"email server\");\nnow_GR.addQuery(\"123TEXTINDEXGROUP321\", \"portal\");\nnow_GR.query();\n```\n\n## Scoped GlideRecord - addQuery\\(String name, String operator, Object value\\)\n\nProvides the ability to build a request, which when executed, returns the rows from the specified table, that match the request.\n\nIf you are familiar with SQL, this method is similar to the \"where\" clause. One or more addQuery\\(\\) calls can be made in a single query; in this case the queries are AND'ed. If any of the query statements need to be OR'ed, use the GlideQueryCondition method [addOrCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md).\n\nAlways test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert\\(\\), update\\(\\), deleteRecord\\(\\), or deleteMultiple\\(\\) method on bad query results can result in data loss.\n\nYou can set the **glide.invalid\\_query.returns\\_no\\_rows** system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when **glide.invalid\\_query.returns\\_no\\_rows** is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term\\(s\\) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see [Available system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_AvailableSystemProperties.md).\n\n**Note:** To enforce query access based on the user, use[addUserQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.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\nname\n\n</td><td>\n\nString\n\n</td><td>\n\nTable field name.\n\n</td></tr><tr><td>\n\noperator\n\n</td><td>\n\nString\n\n</td><td>\n\nQuery operator. The available values are dependent on the data type of the *value* parameter.Numbers:\n\n-   =\n-   !=\n-   &gt;\n-   &gt;=\n-   &lt;\n-   &lt;=\n\n Strings \\(must be in upper case\\):\n\n-   =\n-   !=\n-   IN\n-   NOT IN\n-   STARTSWITH\n-   ENDSWITH\n-   CONTAINS\n-   DOES NOT CONTAIN\n-   INSTANCEOF\n\n**Note:** Use CONTAINS instead of the LIKE operator.\n\n</td></tr><tr><td>\n\nvalue\n\n</td><td>\n\nObject\n\n</td><td>\n\nValue on which to query \\(not case-sensitive\\).\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|GlideQueryCondition|The query condition that was added to the GlideRecord.|\n\n```\nvar rec = new GlideRecord('incident');\nrec.addQuery('active',true);\nrec.addQuery('sys_created_on', \">\", \"2010-01-19 04:05:00\");\nrec.query();\nwhile (rec.next()) {\n  rec.setValue('active', false);\n  gs.info('Active incident ' + rec.getValue('number') + ' closed');\n  rec.update();\n}\n```\n\nUsing the IN operator.\n\n```\nvar now_GR = new GlideRecord('incident');\nnow_GR.addQuery('number','IN','INC00001,INC00002');\nnow_GR.query();\nwhile(now_GR.next()) {\n  //do something....\n}\n```\n\n## Scoped GlideRecord - addSystemEncodedQuery\\(String query\\)\n\nAdds a query using an encoded query string. Use this method to bypass query access.\n\nUse this method when system-level access is intended, so that query ACL enforcement is explicitly bypassed for the user. Use[addUserEncodedQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) to enforce query access.\n\nAdditional methods for system-level access that bypass query ACL checks:\n\n-   [addSystemOrderBy\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [addSystemOrderByDesc\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [addSystemQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [GlideQueryCondition - addSystemCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n-   [GlideQueryCondition - addSystemOrCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n\nFor information on using this method with GlideRecordSecure, see [Enforcing query ACLs](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/p_GlideServerAPIs.md).\n\nAlways test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert\\(\\), update\\(\\), deleteRecord\\(\\), or deleteMultiple\\(\\) method on bad query results can result in data loss.\n\nYou can set the **glide.invalid\\_query.returns\\_no\\_rows** system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when **glide.invalid\\_query.returns\\_no\\_rows** is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term\\(s\\) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see [Available system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_AvailableSystemProperties.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|query|String|An [encoded query string](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows how to return the number value of the first 12 incidents with a priority value of 1 or 2.\n\n```\nvar queryString = \"priority=1^ORpriority=2\";\nvar now_GR = new GlideRecord('incident');\nnow_GR.addSystemEncodedQuery(queryString);\n\nnow_GR.setLimit(12);\nnow_GR.query();\n\nwhile (now_GR.next()) {\n  gs.info(now_GR.getValue('number'));\n}\n```\n\nOutput:\n\n```\n*** Script: INC0002318\n*** Script: INC0000144\n*** Script: INC0006927\n*** Script: INC0003577\n*** Script: INC0006928\n*** Script: INC0000135\n*** Script: INC0005637\n*** Script: INC0003196\n*** Script: INC0002647\n*** Script: INC0004074\n*** Script: INC0003444\n*** Script: INC0001694\n```\n\n## Scoped GlideRecord - addSystemOrderBy\\(String name\\)\n\nSpecifies an orderBy column. Use this method to bypass query access.\n\nUse this method when system-level access is intended, so that query ACL enforcement is explicitly bypassed for the user. Use[addUserOrderBy\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) to enforce query access.\n\nAdditional methods for system-level access that bypass query ACL checks:\n\n-   [addSystemEncodedQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [addSystemQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [GlideQueryCondition - addSystemCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n-   [GlideQueryCondition - addSystemOrCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n\nCall this method more than once to order by multiple columns. Results are arranged in ascending order. To arrange records in descending order, see [addSystemOrderByDesc\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Column name to use to order the records in this GlideRecord object.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows how to order incident records in ascending order by Short Description.\n\n```\nvar queryString = \"priority=1\";\nvar now_GR = new GlideRecord('incident');\n\nnow_GR.addSystemOrderBy('short_description'); // Ascending Order\nnow_GR.addSystemEncodedQuery(queryString);\n\nnow_GR.setLimit(6);\nnow_GR.query();\n\nwhile (now_GR.next()) {\n  gs.info(now_GR.getValue('short_description'));\n}\n```\n\nOutput:\n\n```\n*** Script: Access token revoked\n*** Script: Access token revoked\n*** Script: Account locked, pls reset my password for Linkedin Sales Navigator\n*** Script: Active Directory (AD) synchronization error\n*** Script: Adobe Photoshop & Digital Publishing Instance is down\n*** Script: Application response time is poor when performing any action in ADP Payroll S...\n```\n\n## Scoped GlideRecord - addSystemOrderByDesc\\(String name\\)\n\nSpecifies a descending orderBy column. Use this method to bypass query access.\n\nUse this method when system-level access is intended, so that query ACL enforcement is explicitly bypassed for the user. Use[addUserOrderByDesc\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) to enforce query access.\n\nAdditional methods for system-level access that bypass query ACL checks:\n\n-   [addSystemEncodedQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [addSystemQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [GlideQueryCondition - addSystemCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n-   [GlideQueryCondition - addSystemOrCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n\nCall this method more than once to order by multiple columns. Results are arranged in descending order. To arrange records in ascending order, see [addSystemOrderBy\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Column name to use to order the records in a GlideRecord object.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows how to order incident records in descending order by Short Description.\n\n```\nvar queryString = \"priority=2\";\nvar now_GR = new GlideRecord('incident');\n\nnow_GR.addSystemOrderByDesc('short_description'); //Descending Order\nnow_GR.addSystemEncodedQuery(queryString);\n\nnow_GR.setLimit(6);\nnow_GR.query();\n\nwhile (now_GR.next()) {\n  gs.info(now_GR.getValue('short_description'));\n}\n```\n\nOutput:\n\n```\n*** Script: Xignite U.S. and Global Real Time Quotes upgrade to the latest version\n*** Script: Xignite Company, Market and Industry News Headlines upgrade to the latest ver...\n*** Script: Workday Talent Management Instance relocation from US datacenter to Hongkong ...\n*** Script: Warning displayed while launching Tableau Server\n*** Script: Warning displayed while launching SAP Financial Accounting\n*** Script: Warning displayed while launching Jive Daily\n```\n\n## Scoped GlideRecord - addSystemQuery\\(String name, Object operator, Object value\\)\n\nProvides the ability to build a request, which when executed, returns the rows from the specified table, that match the request. Use this method to bypass query access.\n\nUse this method when system-level access is intended, so that query ACL enforcement is explicitly bypassed for the user. Use[addUserQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) to enforce query access.\n\nAdditional methods for system-level access that bypass query ACL checks:\n\n-   [addSystemEncodedQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [addSystemOrderBy\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [addSystemOrderByDesc\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [GlideQueryCondition - addSystemCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n-   [GlideQueryCondition - addSystemOrCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n\nAlways test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert\\(\\), update\\(\\), deleteRecord\\(\\), or deleteMultiple\\(\\) method on bad query results can result in data loss.\n\nYou can set the **glide.invalid\\_query.returns\\_no\\_rows** system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when **glide.invalid\\_query.returns\\_no\\_rows** is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term\\(s\\) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see [Available system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_AvailableSystemProperties.md).\n\n<table id=\"table_ix2_hvp_dt\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nname\n\n</td><td>\n\nString\n\n</td><td>\n\nTable field name.\n\n</td></tr><tr><td>\n\noperator\n\n</td><td>\n\nObject\n\n</td><td>\n\nQuery operator. The available values are dependent on the data type of the *value* parameter.Numbers:\n\n-   =\n-   !=\n-   &gt;\n-   &gt;=\n-   &lt;\n-   &lt;=\n\nStrings \\(must be in upper case\\):\n\n-   =\n-   !=\n-   IN\n-   NOT IN\n-   STARTSWITH\n-   ENDSWITH\n-   CONTAINS\n-   DOES NOT CONTAIN\n-   INSTANCEOF\n\n**Note:** Use CONTAINS instead of the LIKE operator.\n\nDynamic schema operators:\n\n-   =\n-   !=\n-   &lt;\n-   &gt;\n-   &lt;=\n-   &gt;=\n-   BETWEEN\n-   CONTAINS\n-   DOES\\_NOT\\_CONTAIN\n-   ENDSWITH\n-   GT\\_FIELD\n-   GT\\_OR\\_EQUALS\\_FIELD\n-   IN\n-   ISEMPTY\n-   ISNOTEMPTY\n-   IS\\_NOT\\_NULL\n-   IS\\_NULL\n-   LIKE\n-   LT\\_FIELD\n-   LT\\_OR\\_EQUALS\\_FIELD\n-   MATCHES\n-   NOT\\_IN\n-   NOT\\_LIKE\n-   NOT\\_MATCHES\n-   NSAMEAS\n-   SAMEAS\n-   STARTSWITH\n\n</td></tr><tr><td>\n\nvalue\n\n</td><td>\n\nObject\n\n</td><td>\n\nValue on which to query \\(not case-sensitive\\).\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|[GlideQueryCondition](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)|The query condition that was added to the GlideRecord.|\n\nThe following example shows how to explicitly return all active users named Fred.\n\n```\nvar rec = new GlideRecord('sys_user');\nrec.addSystemQuery(\"first_name\", \"=\", \"Fred\");\nrec.query();\n\nwhile (rec.next()) {\n  gs.info('Active user ' + rec.getValue('last_name'));\n}\n```\n\nOutput:\n\n```\nActive user Luddy\nActive user Kunde\n```\n\n## Scoped GlideRecord - addUserEncodedQuery\\(String query\\)\n\nAdds a query using an encoded query string. Use this method to enforce query access based on the user.\n\nThis method returns only records that the current user has query access to \\(based on ACLs\\).\n\nRelated methods:\n\n-   [addEncodedQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) provides the same functionality without ACL enforcement.\n-   [addSystemEncodedQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) bypasses query access checks.\n\nAdditional methods for enforcing query ACL checks:\n\n-   [addUserOrderBy\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [addUserOrderByDesc\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [addUserQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [GlideQueryCondition - addUserCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n-   [GlideQueryCondition - addUserOrCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n\nFor information on using this method with GlideRecordSecure, see [Enforcing query ACLs](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/p_GlideServerAPIs.md).\n\nAlways test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert\\(\\), update\\(\\), deleteRecord\\(\\), or deleteMultiple\\(\\) method on bad query results can result in data loss.\n\nYou can set the **glide.invalid\\_query.returns\\_no\\_rows** system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when **glide.invalid\\_query.returns\\_no\\_rows** is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term\\(s\\) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see [Available system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_AvailableSystemProperties.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|query|String|An [encoded query string](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows how to return the number value of the first 12 incidents with a priority value of 1 or 2.\n\n```\nvar queryString = \"priority=1^ORpriority=2\";\nvar now_GR = new GlideRecord('incident');\nnow_GR.addUserEncodedQuery(queryString);\n\nnow_GR.setLimit(12);\nnow_GR.query();\n\nwhile (now_GR.next()) {\n  gs.info(now_GR.getValue('number'));\n}\n```\n\nOutput:\n\n```\n*** Script: INC0002318\n*** Script: INC0000144\n*** Script: INC0006927\n*** Script: INC0003577\n*** Script: INC0006928\n*** Script: INC0000135\n*** Script: INC0005637\n*** Script: INC0003196\n*** Script: INC0002647\n*** Script: INC0004074\n*** Script: INC0003444\n*** Script: INC0001694\n```\n\n## Scoped GlideRecord - addUserOrderBy\\(String name\\)\n\nSpecifies an orderBy column. Use this method to enforce query access based on the user.\n\nThis method returns only records that the current user has query access to \\(based on ACLs\\).\n\nRelated methods:\n\n-   [orderBy\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) provides the same functionality without ACL enforcement.\n-   [addSystemOrderBy\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) bypasses query access checks.\n\nAdditional methods for enforcing query ACL checks:\n\n-   [addUserEncodedQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [addUserQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [GlideQueryCondition - addUserCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n-   [GlideQueryCondition - addUserOrCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n\nCall this method more than once to order by multiple columns. Results are arranged in ascending order. To arrange records in descending order, see [addUserOrderByDesc\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Column name to use to order the records in this GlideRecord object.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows how to order incident records in ascending order by Short Description.\n\n```\nvar queryString = \"priority=1\";\nvar now_GR = new GlideRecord('incident');\n\nnow_GR.addUserOrderBy('short_description'); // Ascending Order\nnow_GR.addUserEncodedQuery(queryString);\n\nnow_GR.setLimit(6);\nnow_GR.query();\n\nwhile (now_GR.next()) {\n  gs.info(now_GR.getValue('short_description'));\n}\n```\n\nOutput:\n\n```\n*** Script: Access token revoked\n*** Script: Access token revoked\n*** Script: Account locked, pls reset my password for Linkedin Sales Navigator\n*** Script: Active Directory (AD) synchronization error\n*** Script: Adobe Photoshop & Digital Publishing Instance is down\n*** Script: Application response time is poor when performing any action in ADP Payroll S...\n```\n\n## Scoped GlideRecord - addUserOrderByDesc\\(String name\\)\n\nSpecifies a descending orderBy column. Use this method to enforce query access based on the user.\n\nThis method returns only records that the current user has query access to \\(based on ACLs\\).\n\nRelated methods:\n\n-   [orderByDesc\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) provides the same functionality without ACL enforcement.\n-   [addSystemOrderByDesc\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) bypasses query access checks.\n\nAdditional methods for enforcing query ACL checks:\n\n-   [addUserEncodedQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [addUserQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [GlideQueryCondition - addUserCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n-   [GlideQueryCondition - addUserOrCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n\nCall this method more than once to order by multiple columns. Results are arranged in descending order. To arrange records in ascending order, see [addUserOrderBy\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Column name to use to order the records in a GlideRecord object.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows how to order incident records in descending order by Short Description.\n\n```\nvar queryString = \"priority=2\";\nvar now_GR = new GlideRecord('incident');\n\nnow_GR.addUserOrderByDesc('short_description'); //Descending Order\nnow_GR.addUserEncodedQuery(queryString);\n\nnow_GR.setLimit(6);\nnow_GR.query();\n\nwhile (now_GR.next()) {\n  gs.info(now_GR.getValue('short_description'));\n}\n```\n\nOutput:\n\n```\n*** Script: Xignite U.S. and Global Real Time Quotes upgrade to the latest version\n*** Script: Xignite Company, Market and Industry News Headlines upgrade to the latest ver...\n*** Script: Workday Talent Management Instance relocation from US datacenter to Hongkong ...\n*** Script: Warning displayed while launching Tableau Server\n*** Script: Warning displayed while launching SAP Financial Accounting\n*** Script: Warning displayed while launching Jive Daily\n```\n\n## Scoped GlideRecord - addUserQuery\\(String name, Object operator, Object value\\)\n\nProvides the ability to build a request, which when executed, returns the rows from the specified table that match the request. The calling user must have access to perform the specified query operation on the field for this request to be added. Use this method to enforce query access based on the user.\n\nThis method returns only records that the current user has query access to \\(based on ACLs\\).\n\nRelated methods:\n\n-   [addQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) provides the same functionality without ACL enforcement.\n-   [addSystemQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) bypasses query access checks.\n\nAdditional methods for enforcing query ACL checks:\n\n-   [addUserOrderBy\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [addUserEncodedQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [addUserOrderByDesc\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [GlideQueryCondition - addUserCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n-   [GlideQueryCondition - addUserOrCondition\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n\nAlways test queries on a sub-production instance prior to deploying them on a production instance. An incorrectly constructed encoded query, such as including an invalid field name, produces an invalid query. When the invalid query is run, the invalid part of the query condition is dropped, and the results are based on the valid part of the query, which may return all records from the table. Using an insert\\(\\), update\\(\\), deleteRecord\\(\\), or deleteMultiple\\(\\) method on bad query results can result in data loss.\n\nYou can set the **glide.invalid\\_query.returns\\_no\\_rows** system property to true to have queries with invalid encoded queries return no records. In some cases, the query may still return records in API results even when **glide.invalid\\_query.returns\\_no\\_rows** is set to true. This happens in queries where an invalid query term is used with a WHERE operator. In such queries, the WHERE operator ignores the invalid term\\(s\\) but still interprets and returns the rest of the query statement. For more information about this system property and its functionality, see [Available system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_AvailableSystemProperties.md).\n\n<table id=\"table_ix2_hvp_dt\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nname\n\n</td><td>\n\nString\n\n</td><td>\n\nTable field name.\n\n</td></tr><tr><td>\n\noperator\n\n</td><td>\n\nObject\n\n</td><td>\n\nQuery operator. The available values are dependent on the data type of the *value* parameter.Numbers:\n\n-   =\n-   !=\n-   &gt;\n-   &gt;=\n-   &lt;\n-   &lt;=\n\nStrings \\(must be in upper case\\):\n\n-   =\n-   !=\n-   IN\n-   NOT IN\n-   STARTSWITH\n-   ENDSWITH\n-   CONTAINS\n-   DOES NOT CONTAIN\n-   INSTANCEOF\n\n**Note:** Use CONTAINS instead of the LIKE operator.\n\nDynamic schema operators:\n\n-   =\n-   !=\n-   &lt;\n-   &gt;\n-   &lt;=\n-   &gt;=\n-   BETWEEN\n-   CONTAINS\n-   DOES\\_NOT\\_CONTAIN\n-   ENDSWITH\n-   GT\\_FIELD\n-   GT\\_OR\\_EQUALS\\_FIELD\n-   IN\n-   ISEMPTY\n-   ISNOTEMPTY\n-   IS\\_NOT\\_NULL\n-   IS\\_NULL\n-   LIKE\n-   LT\\_FIELD\n-   LT\\_OR\\_EQUALS\\_FIELD\n-   MATCHES\n-   NOT\\_IN\n-   NOT\\_LIKE\n-   NOT\\_MATCHES\n-   NSAMEAS\n-   SAMEAS\n-   STARTSWITH\n\n</td></tr><tr><td>\n\nvalue\n\n</td><td>\n\nObject\n\n</td><td>\n\nValue on which to query \\(not case-sensitive\\).\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|[GlideQueryCondition](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)|The query condition that was added to the GlideRecord.|\n\nThe following shows how to return only users named Fred that the current user has permission to see.\n\n```\nvar rec = new GlideRecord('sys_user');\nrec.addUserQuery(\"first_name\", \"=\", \"Fred\");\nrec.query();\n\nwhile (rec.next()) {\n  gs.info('Active user ' + rec.getValue('last_name'));\n}\n```\n\nOutput:\n\n```\nActive user Luddy\nActive user Kunde\n```\n\n## Scoped GlideRecord - canCreate\\(\\)\n\nDetermines if the Access Control Rules, which include the user's roles, permit inserting new records in this table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_g2l_vtb_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 user's roles permit creating of records in this table.Valid values:\n\n-   true: Creating permitted\n-   false: Creating is not permitted\n\n</td></tr></tbody>\n</table>This code example writes whether the current user can create records in the Incident table in the system log.\n\n```\nvar now_GR = new GlideRecord('incident');\ngs.info(now_GR.canCreate());\n```\n\n## Scoped GlideRecord - canDelete\\(\\)\n\nDetermines if the Access Control Rules, which include the user's roles, permit deleting records in this table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_pdw_ftb_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 user's roles permit deleting of records in this table.Valid values:\n\n-   true: Deleting permitted\n-   false: Deleting is not permitted\n\n</td></tr></tbody>\n</table>This code example writes whether the current user can delete records in the Incident table in the system log.\n\n```\nvar att = new GlideRecord('sys_attachment');\ngs.info(att.canDelete());\n```\n\n## Scoped GlideRecord - canRead\\(\\)\n\nDetermines if the Access Control Rules \\(ACLs\\) permit reading records in this table. This method evaluates all ACL types, such as user roles, scripted ACLs, ACLs with scripted conditions, and so on.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_zmp_ttb_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 user's roles permit reading of records in this table.Valid values:\n\n-   true: Reading permitted\n-   false: Reading is not permitted\n\n</td></tr></tbody>\n</table>This code example writes whether the current user can read records in the Incident table in the system log.\n\n```\nvar now_GR = new GlideRecord('incident');\ngs.info(now_GR.canRead());\n```\n\n## Scoped GlideRecord - canWrite\\(\\)\n\nDetermines if the Access Control Rules, which include the user's roles, permit editing records in this table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_sq3_ttb_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 user's roles permit writing of records in this table.Valid values:\n\n-   true: Writing permitted\n-   false: Writing is not permitted\n\n</td></tr></tbody>\n</table>This code example writes whether the current user can write records in the Incident table in the system log.\n\n```\nvar now_GR = new GlideRecord('incident');\ngs.info(now_GR.canWrite());\n```\n\n## Scoped GlideRecord - chooseWindow\\(Number firstRow, Number lastRow, Boolean forceCount\\)\n\nSets a range of rows to be returned by subsequent queries.\n\n-   **Using setLimit\\(\\) with chooseWindow\\(\\)**\n\n    The setLimit\\(\\) method implicitly calls the chooseWindow\\(\\) method and might cause unexpected results when used with chooseWindow\\(\\) in a query.\n\n    -   If the chooseWindow\\(\\) method is called first, its record window is overwritten by the setLimit\\(\\) method.\n\n        Using the following lines in a query returns 100 records starting at row 1:\n\n        ```\n        grIncident.chooseWindow(20,30);\n        grIncident.setLimit(100);\n        ```\n\n    -   If the setLimit\\(\\) method is called first, the window set by chooseWindow\\(\\) is used and the limit is overwritten.\n\n        Using the following lines in a query returns 10 records starting at row 21:\n\n        ```\n        grIncident.setLimit(5);\n        grIncident.chooseWindow(20,30);\n        ```\n\n        **Note:** Running query\\(\\) with the chooseWindow\\(\\) method triggers a `COUNT(*)` query, which can result in slow performance on tables with a large number of records. You can use setLimit\\(\\) before chooseWindow\\(\\) to skip running the `COUNT(*)` query, but the same performance benefit is achievable using setNoCount\\(\\).\n\n\nSee also:\n\n-   [query\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [setLimit\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [setNoCount\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.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\nfirstRow\n\n</td><td>\n\nNumber\n\n</td><td>\n\nZero-based index of the starting row for the range, inclusive. \\(A value of 0 returns the first row.\\)\n\n</td></tr><tr><td>\n\nlastRow\n\n</td><td>\n\nNumber\n\n</td><td>\n\nZero-based index of the ending row for the range, exclusive.For example, if **firstRow** = 1 and **lastRow** = 5, four records are returned \\(2-5\\).\n\n</td></tr><tr><td>\n\nforceCount\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nOptional. Flag that indicates whether to force a row count query. In most implementations of this call, the row count is performed. There are some outlying cases, such as text searches, were a row count is not performed. Setting this flag ensures that the row count occurs.Valid values:\n\n-   true: Row count always occurs.\n-   false: Row count occurs if implemented in normal execution of method.\n\n Default: false\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThis example shows how to return records 3 and 4 from the Incident \\[incident\\] table.\n\n```\nvar now_GR = new GlideRecord('incident');\nnow_GR.orderBy('number');\nnow_GR.chooseWindow(2, 4);\nnow_GR.query();\nwhile (now_GR.next()) {\n  gs.info(now_GR.getValue('number') + ' is within window');\n}\n```\n\nOutput:\n\n```\n*** Script: INC0000003 is within window\n*** Script: INC0000004 is within window\n```\n\n## Scoped GlideRecord - deleteMultiple\\(\\)\n\nDeletes all records that satisfy the query.\n\nThis method does not delete attachments.\n\nDo not use deleteMultiple\\(\\) on tables with currency fields. Always delete each record individually. Also, do not use this method with the chooseWindow\\(\\) or setLimit\\(\\) methods when working with large tables. The setLimit\\(\\) method does not limit the number of records that are deleted with deleteMultiple\\(\\). All records returned by the query are deleted regardless of setLimit\\(\\).\n\nThe **glide.db.forced.chunk.threshold** system property sets the threshold above which forces chunk record deletions and updates. Chunking helps to prevent non-primary key deletions on huge tables from causing replication problems. For more information, see [Available system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_AvailableSystemProperties.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to delete all inactive records from the Incident table.\n\n```\nvar now_GR = new GlideRecord('incident');\nnow_GR.addQuery('active','false');\nnow_GR.query();\nnow_GR.deleteMultiple();\n```\n\n## Scoped GlideRecord - deleteRecord\\(\\)\n\nDeletes the current record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_rrm_4tb_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 record was successfully deleted.Valid values:\n\n-   true: Record was deleted.\n-   false: No record was found to delete.\n\n</td></tr></tbody>\n</table>This example shows how to delete a specified record from the Incident table.\n\n```\nvar now_GR = new GlideRecord('incident');\n//to delete one record\nif (now_GR.get('99ebb4156fa831005be8883e6b3ee4b9'))\n    now_GR.deleteRecord();\n```\n\nThis example shows how to delete a record from the Incident table immediately after it is inserted. The incident GlideRecord must be reloaded after the insert before it can be deleted.\n\n```\nvar grTicket = new GlideRecord('incident');\ngrTicket.initialize();\ngrTicket.short_description = 'Example ticket';\ngrTicket.work_notes = 'An update about the ticket';\nvar ins_sys_id = grTicket.insert(); // Insert the record\ngrTicket.get(ins_sys_id); // Reload the inserted record\ngs.info(grTicket.deleteRecord()); // Delete the record\n```\n\nOutput:\n\n```\ntrue\n```\n\n## Scoped GlideRecord - disableSysIdInOptimization\\(\\)\n\nDisables the default optimization that prevents an extra database query from running when a user passes in a large number of sys\\_ids, such as `grIncident.addQuery('sys_id', 'IN', listOf200SysIds)`.\n\nThis method only effects the GlideRecord on which it’s called. To modify the sys\\_id limit optimization for all GlideRecords, adjust the value in the **glide.db.first\\_pass\\_sys\\_id\\_list\\_size.max** system property \\(default 100\\).\n\nIf you don't either call this method or adjust the **glide.db.first\\_pass\\_sys\\_id\\_list\\_size.max** system property and pass a list that contains more sys\\_id entries than defined in **glide.db.first\\_pass\\_sys\\_id\\_list\\_size.max**, the returned value from GlideRecord.getRowCount\\(\\) may be incorrect.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following code example shows how to use the disableSysIdInOptimiation\\(\\) method to disable the sys\\_id limit optimization when passing an Incident sys\\_id list that contains 200 entries.\n\n```\nvar listOf200SysIds = [ ... ]; // 200 comma separated sys_ids\nvar grIncident = new GlideRecord('incident');\ngrIncident.addQuery('sys_id', 'IN', listOf200SysIds);\ngrIncident.disableSysIdInOptimization(); // Rowcount could be incorrect without this method call\ngrIncident.query();\nif (grIncident.next())\n    gs.info(\"Rowcount: \" + grIncident.getRowCount());\n```\n\nOutput:\n\n```\nRowcount: 200\n```\n\n## Scoped GlideRecord - get\\(Object name, Object value\\)\n\nReturns the specified record in the current GlideRecord object.\n\nThis method accepts either one or two parameters. If only a single parameter is passed in, the method assumes that it is the sys\\_id of the desired record. If not found, it then tries to match the value against the display value. If two parameters are passed in, the first is the name of the column within the GlideRecord to search. The second is the value to search for. If multiple records are found, use next\\(\\) to access the additional records.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|Object|Optional. Name of the instantiated GlideRecord column to search for the specified **value** parameter. If only a single parameter is passed in, the method assumes that this parameter is the sys\\_id or display value.|\n|value|Object|Value to match. For calculated fields, the value is matched as is rather than running a calculation on a scripted default value for a field in the record.|\n\n<table id=\"table_qpt_3f5_jq\" 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\nIndicates whether the requested record was located:-   true: record was found\n-   false: record was not found\n\n</td></tr></tbody>\n</table>This example shows how to obtain an incident record by passing in the sys\\_id.\n\n```\nvar grIncident = new GlideRecord('incident');\nvar returnValue = grIncident.get('99ebb4156fa831005be8883e6b3ee4b9');\ngs.info(returnValue); // logs true or false\ngs.info(grIncident.short_description); // logs Incident Short description\n```\n\nThis example shows how to obtain an incident record by passing the field to search \\(caller\\_id.name\\) and the value to match within that field.\n\n```\nvar grIncident = new GlideRecord('incident');\nvar returnValue = grIncident.get('caller_id.name','Sylivia Wayland');\ngs.info(returnValue); // logs true or false\ngs.info(grIncident.getValue('number')); // logs Incident Number\n```\n\n## Scoped GlideRecord - getAttribute\\(String fieldName\\)\n\nReturns the dictionary attributes for the specified field.\n\n|Name|Type|Description|\n|----|----|-----------|\n|fieldName|String|Field name for which to return the dictionary attributes|\n\n|Type|Description|\n|----|-----------|\n|String|Dictionary attributes|\n\n```\ndoit();\nfunction doit() {\n  var now_GR = new GlideRecord('sys_user');\n  now_GR.query(\"user_name\",\"admin\");\n  if (now_GR.next()) {\n    gs.info(\"we got one\");\n    gs.info(now_GR.location.getAttribute(\"tree_picker\"));\n  }\n}\n```\n\n## Scoped GlideRecord - getClassDisplayValue\\(\\)\n\nReturns the current table's label.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Label that identifies the table.|\n\nThis example prints the label of the passed in table.\n\n```\n// Display the incident table label\nvar now_GR = new GlideRecord(\"incident\");\nvar value = now_GR.getClassDisplayValue();\ngs.info(\"The table label is \" + value + \".\");\n```\n\nOutput:\n\n```\nThe table label is Incident.\n```\n\n## Scoped GlideRecord - getDisplayValue\\(\\)\n\nRetrieves the display value for the current record.\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|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Display value for the current record.|\n\nThis example writes the display value of a specified incident record into the log.\n\n```\nvar now_GR = new GlideRecord('incident');\nnow_GR.get('sys_id','<sys_id>');\ngs.info(now_GR.getDisplayValue());\n```\n\nOutput:\n\n```\nINC0000050\n```\n\n## Scoped GlideRecord - getED\\(\\)\n\nReturns the element's descriptor.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|GlideElementDescriptor|The element's descriptor.|\n\nThis example shows how to retrieve the name field for an incident GlideRecord.\n\n```\nvar grInc = new GlideRecord('incident');\ngrInc.get('sys_id','ef43c6d40a0a0b5700c77f9bf387afe3');\n\nvar field = grInc.getElement('priority');\nvar ed = field.getED();\n\nvar isEdge = ed.getLabel();\ngs.info(\"Label is - \" + isEdge);\n```\n\nOutput:\n\n```\nLabel is - Priority\n```\n\n## Scoped GlideRecord - getElement\\(String fieldName\\)\n\nRetrieves the GlideElement object for the specified field.\n\nThe value returned by this method is a complete GlideElement object. The results are the equivalent of dot-walking a field value. For example, `now_GR.getElement('short_description')` provides the same result as `nowGR.short_description`.\n\nIn most cases, don’t use dot-walking to get values from a record. Dot-walking retrieves the entire object instead of the field value. Retrieving the object uses more storage and might cause undesirable results when used in arrays or in Service Portal.\n\nInstead of retrieving the entire object, you can use one of the following methods to copy the field values:\n\n-   [getValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [getDisplayValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n\nIf dot-walking through a GlideElement object is necessary, use the toString\\(\\) method to retrieve values. For example, you might need the current caller's manager sys\\_id to set another reference field. The following example shows how to get the string value instead of the entire object:\n\n```\nvar mgr = current.caller_id.manager.toString();\n```\n\nSee also:\n\n-   [GlideElement – toString\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md)\n-   [getElements\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|fieldName|String|Column name for which to return the GlideElement object.|\n\n|Type|Description|\n|----|-----------|\n|GlideElement|The GlideElement for the specified column of the current record. Each object describes a field in the current GlideRecord.|\n\nThe following example shows how to add a new incident record with details in the **Short Description** field.\n\n```\nvar elementName = 'short_description'; \nvar now_GR = new GlideRecord('incident'); \nnow_GR.newRecord(); \nnow_GR.setValue(elementName, \"My DB is not working\");\nnow_GR.insert();\n \nvar sdesc = now_GR.getElement('short_description');\ngs.info(sdesc.getValue());\n```\n\nOutput:\n\n```\nMy DB is not working\n```\n\n## Scoped GlideRecord - getElements\\(\\)\n\nReturns an array of GlideElement objects. Each object describes a field in the current GlideRecord.\n\nIf dot-walking through a GlideElement object is necessary, use the toString\\(\\) method to retrieve values. For example, you might need the current caller's manager sys\\_id to set another reference field. The following example shows how to get the string value instead of the entire object:\n\n```\nvar mgr = current.caller_id.manager.toString();\n```\n\nSee also:\n\n-   [GlideElement – toString\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md)\n-   [getElement\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Array|Array of [GlideElement](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementScopedAPI.md) objects. Each object describes a field in the current GlideRecord.|\n\nThe following example displays the value of the name field for the five most recent records created in the Question \\[question\\] table.\n\n```\nvar now_GR = new GlideRecord('question');\nvar elementArr = now_GR.getElements();\nnow_GR.orderByDesc('sys_created_on');\nnow_GR.setLimit(5);\nnow_GR.query();\n\nwhile (now_GR.next()){\n  var qNames = now_GR.name.toString();\n  elementArr.push(qNames);\n  gs.info(qNames);\n}\n```\n\nOutput:\n\n```\ndelivery_time_var\ndelivery_time\nsequence\npriority\nassigned_group\n```\n\n## Scoped GlideRecord - getEncodedQuery\\(\\)\n\nRetrieves the query condition of the current result set as an encoded query string.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|An [encoded query string](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).|\n\n```\nvar now_GR = new GlideRecord('incident'); \nnow_GR.addQuery('active', true);\nnow_GR.addQuery('priority', 1); \nnow_GR.query(); \nvar encodedQuery = now_GR.getEncodedQuery(); \ngs.info(encodedQuery);\n```\n\nOutput:\n\n```\nactive=true^priority=1\n```\n\n## Scoped GlideRecord - getLabel\\(\\)\n\nReturns the field's label.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Field's label|\n\n```\ntemplate.print(\"Summary of Requested items:\\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() \n    + \" at $\" + nicePrice + \" each \\n\");\n  template.print(\"    Options:\\n\");\n  for (key in now_GR.variables) {\n  var now_V = now_GR.variables[key];\n    if(now_V.getGlideObject().getQuestion().getLabel() != '') {\n      template.space(4);\n      template.print('     ' +  now_V.getGlideObject().getQuestion().getLabel() + \" = \" \n        + now_V.getDisplayValue() + \"\\n\");  \n    }\n  }\n}\n```\n\n## Scoped GlideRecord - getLastErrorMessage\\(\\)\n\nRetrieves the last error message. If there is no last error message, null is returned.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The last error message as a string.|\n\n```\n// Setup a data policy where short_description field in incident is mandatory\nvar now_GR = new GlideRecord('incident');\nnow_GR.insert(); // insert without data in mandatory field\nvar errormessage = now_GR.getLastErrorMessage(); \ngs.info(errormessage);\n```\n\nOutput:\n\n```\nData Policy Exception: Short description is mandatory\n```\n\n## Scoped GlideRecord - getLink\\(Boolean noStack\\)\n\nRetrieves the link to the current record.\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\nnoStack\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag indicating whether to append the sysparm\\_stack parameter to the returned link. This parameter specifies the page to visit after closing the current link. Valid values:\n\n-   true: Do not attach the sysparm\\_stack parameter.\n-   false: Attach the sysparm\\_stack parameter.\n\nIf true, the sysparm\\_stack parameter is not appended to the link.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Link to the current record.|\n\nThis example queries all Incident records with a priority of \"1\" and writes the servlet URI and the current record's link to the system log.\n\n```\nvar now_GR = new GlideRecord('incident');\nnow_GR.addActiveQuery();\nnow_GR.addQuery(\"priority\", 1);\nnow_GR.query();\nnow_GR.next();\ngs.info(gs.getProperty('glide.servlet.uri') + now_GR.getLink(false));\n```\n\nOutput:\n\n```\nhttps://instance.service-now.com/incident.do?sys_id=46e2fee9a9fe19810049b49dee0daf58&sysparm_stack=incident_list.do?sysparm_query=active=true\n```\n\n## Scoped GlideRecord - getRecordClassName\\(\\)\n\nRetrieves the class name for the current record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The class name.|\n\n```\nvar now_GR = new GlideRecord('incident'); \nvar recordClassName = now_GR.getRecordClassName(); \ngs.info(recordClassName);\n```\n\nOutput:\n\n```\nincident\n```\n\n## Scoped GlideRecord - getRowCount\\(\\)\n\nRetrieves the number of rows \\(records\\) in the current GlideRecord object.\n\n**Note:** GlideRecord returns matching records, so it might not be as efficient as GlideAggregate when you only need the number of records. If you only need a record count and aren’t iterating over the matching records, use GlideAggregate.\n\n-   **Retrieving the number of records in GlideRecord or GlideAggregate**\n\n    The GlideRecord getRowCount\\(\\) and [GlideAggregate getAggregate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideAggregateScopedAPI.md) APIs offer similar information. Use the following criteria to determine which option is best for you.\n\n    -   The GlideRecord getRowCount\\(\\) method tells you how many records have been returned from a query along with the records themselves. If you need the number of records in the result set before or after you iterate over the set to perform actions on the records, use this method.\n    -   The GlideAggregate getAggregate\\(\\) method retrieves only a count of records matching the query, excluding the actual records. The aggregate must be set on the GlideAggregate object before issuing the query.\n    Retrieving the records and count with GlideRecord getRowCount\\(\\)\n\n    The following example shows how to get the total number of active incidents with GlideRecord getRowCount\\(\\):\n\n    ```\n    var incident = new GlideRecord(\"incident\");\n    incident.addQuery(\"active\", true);\n    incident.query();\n     \n    gs.info(\"*** Total number of active incidents: {0}\", incident.getRowCount());\n    ```\n\n    Retrieving only the number of records with GlideAggregate getAggregate\\(\\)\n\n    The following example shows how to return only the number of records. Because this method doesn’t use the matching records, it’s much more efficient to use an aggregate query and return just the count.\n\n    ```\n    var incident = new GlideAggregate(\"incident\");\n    incident.addQuery(\"active\", true);\n    incident.addAggregate(\"COUNT\");\n    incident.query();\n     \n    if (incident.next())\n        gs.info(\"*** Total number of active incidents: {0}\", incident.getAggregate(\"COUNT\"));\n    ```\n\n    Deciding which option is best for your solution\n\n    If you only want to retrieve the number of records, the GlideAggregate getAggregate\\(\\) method is the best option. To use the individual records and retrieve the number of results, use GlideRecord getRowCount\\(\\), because a single query provides this functionality.\n\n\n**Note:** If you want to use the getRowCount\\(\\) method when using `sys_id IN` with more than 100 sys\\_id values, such as `grIncident.addQuery('sys_id', 'IN', listOf200SysIds)`, you must either:\n\n-   Call the disableSysIdInOptimization\\(\\) method on the GlideRecord.\n-   Or, adjust the **glide.db.first\\_pass\\_sys\\_id\\_list\\_size.max** system property to a value higher than the number of sys\\_ids in the list.\n\nIn addition, ensure that you call the .next\\(\\) method before calling the getRowCount\\(\\) method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|Number of rows in the current GlideRecord.|\n\nThe following example shows how to get the number of incidents from the Incident \\[incident\\] table.\n\n```\nvar numberOfIncidents = new GlideRecord('incident');\nnumberOfIncidents.query();\ngs.info(\"Records in incident table: \" + numberOfIncidents.getRowCount());\n```\n\nOutput:\n\n```\nRecords in incident table: 6920\n```\n\nThe following code example shows how to use the disableSysIdInOptimiation\\(\\) method to disable the sys\\_id limit optimization when passing an Incident sys\\_id list that contains 200 entries.\n\n```\nvar listOf200SysIds = [ ... ]; // 200 comma separated sys_ids\nvar grIncident = new GlideRecord('incident');\ngrIncident.addQuery('sys_id', 'IN', listOf200SysIds);\ngrIncident.disableSysIdInOptimization(); // Rowcount could be incorrect without this method call\ngrIncident.query();\nif (grIncident.next())\n    gs.info(\"Rowcount: \" + grIncident.getRowCount());\n```\n\nOutput:\n\n```\nRowcount: 200\n```\n\n## Scoped GlideRecord - getTableName\\(\\)\n\nRetrieves the name of the table associated with the GlideRecord.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The table name|\n\n```\nvar now_GR = new GlideRecord('incident');\ngs.info(now_GR.getTableName());\n```\n\n## Scoped GlideRecord - getUniqueValue\\(\\)\n\nGets the primary key of the record, which is usually the sys\\_id unless otherwise specified.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The unique primary key as a String, or null if the key is null.|\n\n```\nvar now_GR = new GlideRecord('kb_knowledge');\nnow_GR.query();\nnow_GR.next();\nvar uniqueid = now_GR.getUniqueValue();\ngs.info(uniqueid);\n```\n\n## Scoped GlideRecord - getValue\\(String name\\)\n\nRetrieves the string value of an underlying element in a field.\n\n**Note:** If the Field Encryption Enterprise plugin is enabled and the instance has access to the key, this method returns clear text values from encrypted fields. If the instance does not have access to the key, this method returns the encrypted value. For more information, see [Platform Encryption](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/encryption-landing.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|The name of the field to get the value from.|\n\n|Type|Description|\n|----|-----------|\n|String|The string value of the underlying element. Returns null if the field is empty or the field does not exist. Boolean values return as `\"0\"` and `\"1\"` string values instead of false and true.|\n\n```\nvar now_GR = new GlideRecord('incident'); \nnow_GR.orderBy('number');\nnow_GR.query('active','true'); \nnow_GR.next(); \ngs.info(now_GR.getValue('number'));\n```\n\nOutput:\n\n```\nINC0000002\n```\n\n## Scoped GlideRecord - GlideRecord\\(String tableName\\)\n\nCreates an instance of the GlideRecord class for the specified table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|tableName|String|The table to be used.|\n\n```\nvar now_GR = new GlideRecord('incident');\n```\n\n## Scoped GlideRecord - hasNext\\(\\)\n\nDetermines if there are any more records in the GlideRecord object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if there are more records in the query result set.|\n\n```\nvar rec = new GlideRecord('incident'); \nrec.query(); \nif (rec.hasNext()) { \n  gs.info(\"Table is not empty\"); \n}\n```\n\n## Scoped GlideRecord - insert\\(\\)\n\nInserts a new record using the field values that have been set for the current record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the inserted record, or null if the record is not inserted.|\n\n```\nvar now_GR = new GlideRecord('incident');\nnow_GR.initialize();\nnow_GR.setValue('name', 'New Incident');\nnow_GR.setValue('description', 'Incident description');\nnow_GR.insert();\n```\n\nOutput:\n\n```\n138fb4111b4d4d907cf30d03cd4bcb57\n```\n\n## Scoped GlideRecord - initialize\\(\\)\n\nCreates an empty record suitable for population before an insert.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar grIncident = new GlideRecord('incident');\ngrIncident.initialize();\ngrIncident.setValue('short_description', 'New Incident');\ngrIncident.setValue('description', 'Incident description');\ngrIncident.insert();\n```\n\n## Scoped GlideRecord - isActionAborted\\(\\)\n\nChecks to see if the current database action is to be aborted.\n\nisActionAborted\\(\\) is initialized \\(set to false\\) for new threads and by the next\\(\\) method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_hqg_mvt_vr\" 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 if the current database action is to be aborted.Valid values:\n\n-   true: The current database action is to be aborted.\n-   false: The current database action is not to be aborted.\n\n</td></tr></tbody>\n</table>```\nvar now_GR = new GlideRecord('incident');\n \ngs.info(now_GR.isActionAborted());\n```\n\nOutput:\n\n```\nfalse\n```\n\n## Scoped GlideRecord - isEncodedQueryValid\\(String query\\)\n\nVerifies whether the specified encoded query is valid.\n\nIf the specified encoded query is valid, then the query is applied, just as if you had called [addEncodedQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md). If the specified encoded query is invalid, then `sys_idNotValidnull` is added as the encoded query.\n\n**Note:** This method has been deprecated and replaced with the [isValidEncodedQuery\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) method which does not execute the query.\n\n|Name|Type|Description|\n|----|----|-----------|\n|query|String|Encoded query to validate. See [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).|\n\n<table id=\"table_obb_bv4_2gb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the specified encoded query is valid.-   true: Passed-in encoded query is valid.\n-   false: Passed-in encoded query is not valid.\n\n</td></tr></tbody>\n</table>This code example shows how to validate an encoded query and then execute logic if the query is valid.\n\n```\nvar now_GR = new GlideRecord('incident_sla');\nvar isValidQuery = now_GR.isEncodedQueryValid('inc_impact=1^taskslatable_active=true');\nif (isValidQuery) {\n  now_GR.query();\n  .\n  .\n  .\n}\n```\n\n## Scoped GlideRecord - isNewRecord\\(\\)\n\nChecks if the current record is a new record that has not yet been inserted into the database.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the record is new and has not been inserted into the database.|\n\n```\nvar now_GR = new GlideRecord(\"x_app_table\"); \nnow_GR.newRecord(); // create a new record and populate it with default values\ngs.info(now_GR.isNewRecord());\n```\n\n## Scoped GlideRecord - isValid\\(\\)\n\nDetermines if the current table is valid or if the record was successfully retrieved.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_qpt_3f5_jq\" 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 if the table is valid or if the record was successfully retrieved.Possible values:\n\n-   true: Table is valid or the record was successfully retrieved.\n-   false: Table is invalid or the record was not successfully retrieved.\n\n</td></tr></tbody>\n</table>```\nvar comment_GR = new GlideRecord('cf_comment');\nvar commentId = '99ebb4156fa831005be8883e6b3ee4b9';\ncomment_GR.get(commentId);\ngs.info(comment_GR.isValid());\n```\n\n## Scoped GlideRecord - isValidEncodedQuery\\(String query\\)\n\nVerifies whether the syntax of the encoded query is correct.\n\nWhen passing an empty string \\(`\"\"`\\) as the provide query:\n\n-   The empty string \\(`\"\"`\\) represents the absence of a query and returns false.\n-   Calling `GlideRecord.addEncodedQuery(\"\")` followed by `GlideRecord.query()` returns all rows. The query method is similar to a SQL SELECT statement. In SQL, when using \"SELECT \\* FROM foo WHERE X\", the value X represents the query. If no query value is provided, all records are returned \\(e.g., SELECT \\* FROM foo\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|query|String|Encoded query to validate. See [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).|\n\n<table id=\"table_vrg_zqs_j5b\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the specified encoded query is valid.-   true: Passed-in encoded query is valid.\n-   false: Passed-in encoded query is not valid.\n\n</td></tr></tbody>\n</table>This code example shows how to check if the encoded query is valid.\n\n```\nvar queryString = \"priority=1^ORpriority=2\";\nvar now_GR = new GlideRecord('incident');\nvar isValidQuery = now_GR.isValidEncodedQuery(queryString);\nif (isValidQuery) {\n  now_GR.addEncodedQuery(queryString);\n  now_GR.query();\n  .\n  .\n  .\n}\n```\n\n## Scoped GlideRecord - isValidField\\(String columnName\\)\n\nDetermines if the specified field is defined in the current table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|columnName|String|The name of the field.|\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the field is defined for the current table.|\n\n```\nvar now_GR = new GlideRecord('incident'); \nnow_GR.initialize(); \ngs.info(now_GR.isValidField(\"short_description\"));\n```\n\n## Scoped GlideRecord - isValidRecord\\(\\)\n\nDetermines if a record was actually returned by the query/get record operation.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_qpt_3f5_jq\" 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 record was actually returned by the query/get operation.Valid values:\n\n-   true: Record returned by query/get operation.\n-   false: End of record set, no record returned.\n\n</td></tr></tbody>\n</table>```\nvar rec = new GlideRecord('incident');\nrec.query();\nwhile (rec.next()) { \n  gs.info(rec.number + ' exists');\n}\ngs.info(rec.isValidRecord());\n```\n\n## Scoped GlideRecord - isView\\(\\)\n\nVerifies whether the record was created in a view or a table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_obb_bv4_2gb\" 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 record was created in table that is a view.-   true: The record was created in a view.\n-   false: The record was created in a table.\n\n</td></tr></tbody>\n</table>This code example shows how to determine if a GlideRecord was created in a view or a table.\n\n```\nvar mySLA = new GlideRecord('incident_sla');\n\nif (mySLA.isView() == true){\n   gs.info('This record was created in a view.');\n} else {\n   gs.info('This record was created in a table.');\n}\n```\n\nOutput:\n\n```\nThis record was created in a view.\n```\n\n## Scoped GlideRecord - newRecord\\(\\)\n\nCreates a new GlideRecord record, sets the default values for the fields, and assigns a unique ID to the record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar now_GR = new GlideRecord(\"x_app_table\"); \nnow_GR.newRecord(); \ngs.info(now_GR.isNewRecord());\n```\n\nOutput:\n\n```\ntrue\n```\n\n## Scoped GlideRecord - next\\(\\)\n\nMoves to the next record in the GlideRecord object.\n\n**Note:** This method fails if there is a field in the table called \"next\". If that is the case, use the method [\\_next\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_qpt_3f5_jq\" 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 if there is a \"next\" record in the GlideRecord. Valid values:\n\n-   true: Move to the next record was successful.\n-   false: No more records in the result set.\n\n</td></tr></tbody>\n</table>```\nvar rec = new GlideRecord('incident');\nrec.query();\nwhile (rec.next()) {\n gs.info(rec.getValue('number') + ' exists');\n}\n```\n\nOutput:\n\n```\nINC0010112 exists\nINC0010114 exists\nINC0010119 exists\nINC0010127 exists\n```\n\n## Scoped GlideRecord - \\_next\\(\\)\n\nMoves to the next record in the GlideRecord. Provides the same functionality as next\\(\\), use this method if the GlideRecord has a column named next.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_f3x_4yj_my\" 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 there are more records in the query set.Possible values:\n\n-   true: More records in the query set.\n-   false: No more records in the query set.\n\n</td></tr></tbody>\n</table>The following example shows how to list each record in the Incidents \\[incident\\] table.\n\n```\nvar rec = new GlideRecord('incident');\nrec.query();\nwhile (rec._next()) {\n  gs.info(rec.getValue('number') + ' exists');\n}\n```\n\nOutput:\n\n```\nINC0000060 exists\nINC0009002 exists\nINC0000009 exists\nINC0000010 exists\nINC0000011 exists\nINC0000012 exists\n...\n```\n\n## Scoped GlideRecord - operation\\(\\)\n\nDetermines if an operation is insert, update, or delete.\n\nKnowing the operation enables using current.operation\\(\\) to make a generic business rule which can handle each operation uniquely.\n\nFor information on using the global variable current, refer to [Global variables in business rules](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/business-rules-classic/c_BusinessRules.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"gr-operation-returns\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nThe current operation.Possible values:\n\n-   delete\n-   insert\n-   update\n\n</td></tr></tbody>\n</table>The following example shows how to use this method in a business rule. The operation\\(\\) method detects which operation triggered an event and performs a different action depending for update and insert operations.\n\n```\nif(current.operation() == \"update\") {\n  current.updates ++; } \nif(current.operation() == \"insert\") {\n  current.updates = 0; }\n```\n\n## Scoped GlideRecord - orderBy\\(String name\\)\n\nSpecifies an orderBy column.\n\nCall this method more than once to order by multiple columns. Results are arranged in ascending order. To arrange records in descending order, see [Scoped GlideRecord - orderByDesc\\(String name\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md).\n\n**Note:** To enforce query access based on the user, use[addUserOrderBy\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Column name to use to order the records in this GlideRecord object.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how to order incident records in ascending order by Short Description.\n\n```\nvar queryString = \"priority=2\";\nvar now_GR = new GlideRecord('incident');\nnow_GR.orderBy('short_description'); // Ascending Order\nnow_GR.addEncodedQuery(queryString);\nnow_GR.query();\nwhile (now_GR.next()) {\n  gs.info(now_GR.getValue('short_description'));\n}\n```\n\nOutput:\n\n```\nCan't launch 64-bit Windows 7 virtual machine\nCan't log into SAP from my laptop today\nNetwork storage unavailable\nPlease remove the latest hotfix from my PC\n```\n\n## Scoped GlideRecord - orderByDesc\\(String name\\)\n\nSpecifies a descending orderBy column.\n\nCall this method more than once to order by multiple columns. Results are arranged in descending order. To arrange records in ascending order, see [Scoped GlideRecord - orderBy\\(String name\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md).\n\n**Note:** To enforce query access based on the user, use[addUserOrderByDesc\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Column name to use to order the records in a GlideRecord object.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how to order incident records in descending order by Short Description.\n\n```\nvar queryString = \"priority=2\";\nvar now_GR = new GlideRecord('incident');\nnow_GR.orderByDesc('short_description'); //Descending Order\nnow_GR.addEncodedQuery(queryString);\nnow_GR.query();\nwhile (now_GR.next()) {\n  gs.info(now_GR.getValue('short_description'));\n}\n```\n\nOutput:\n\n```\nPlease remove the latest hotfix from my PC\nNetwork storage unavailable\nCan't log into SAP from my laptop today\nCan't launch 64-bit Windows 7 virtual machine\n```\n\n## Scoped GlideRecord - query\\(String field, String value\\)\n\nRuns a query against the table based on the filters specified in the query methods such as addQuery\\(\\) and addEncodedQuery\\(\\).\n\nThis method queries the GlideRecord table as well as any references of the table. For more information, see [Querying tables in script](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/c_UsingGlideRecordToQueryTables.md).\n\n**Note:** This method fails if there is a field in the table called \"query\". If that is the case, use the[\\_query\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md) method instead.\n\nSee the [GlideRecord](https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_scripting_utah_scripting_in_servicenow/app_store_learnv2_scripting_utah_server_side_scripting/app_store_learnv2_scripting_utah_gliderecord) article for details on building and running queries.\n\nSee also:\n\n-   [GlideAggregate - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideAggregateScopedAPI.md)\n-   [GlideQuery - Scoped, Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideQueryGlobalAPI.md)\n-   [GlideQueryCondition - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n\n<table id=\"id_nxt_s5d_lpb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nname\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional - must also specify a value parameter. Name of the field to search for the value specified in the value parameter.**Note:** This method is typically run without arguments, but you can specify a name-value pair to filter records containing the specified values. If the parameters are specified, the \"name=value\" condition is added to the query.\n\n</td></tr><tr><td>\n\nvalue\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional - must also specify a field parameter. Value to search for in the specified field parameter.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how to scan the System Dictionary \\[sys\\_dictionary\\] for tables with a query field.\n\n```\nvar tableArr = [];\n\nvar now_GR = new GlideRecord('sys_dictionary');\nnow_GR.addQuery('element', 'query');\nnow_GR.setLimit(6);\n\nnow_GR.query();\n\nwhile(now_GR.next()){\n   tableArr.push(now_GR.name.getValue());\n};\n\ngs.info('The following tables have a field column called \"query\":');\n\nfor (i = 0; i < tableArr.length; i++) {\n   gs.info(tableArr[i]);\n};\n```\n\nOutput:\n\n```\nThe following tables have a field column called \"query\":\ncmdb_convert_bulk_services\ncmdb_multisource_query_status\ncmdb_qb_result_base\ncmdb_qb_table_mapping\ndiscovery_probes_cim_query\nkb_feedback\n```\n\n## Scoped GlideRecord - \\_query\\(String field, String value\\)\n\nRuns a query against the table based on the filters specified in the query methods such as addQuery\\(\\) and addEncodedQuery\\(\\). This method is intended to be used on tables in which there's a column named \"query\", which might cause errors running the query\\(\\) method.\n\nThis method queries the GlideRecord table as well as any references of the table. For more information, see [Querying tables in script](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/c_UsingGlideRecordToQueryTables.md).\n\nSee the [GlideRecord](https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_scripting_utah_scripting_in_servicenow/app_store_learnv2_scripting_utah_server_side_scripting/app_store_learnv2_scripting_utah_gliderecord) article for details on building and running queries.\n\nSee also:\n\n-   [GlideAggregate - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideAggregateScopedAPI.md)\n-   [GlideQuery - Scoped, Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/GlideQueryGlobalAPI.md)\n-   [GlideQueryCondition - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideQueryConditionScopedAPI.md)\n\n<table id=\"id_a3y_t5d_lpb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nname\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional - must also specify a value parameter. Name of the field to search for the value specified in the value parameter.**Note:** This method is typically run without arguments, but you can specify a name-value pair to filter records containing the specified values. If the parameters are specified, the \"name=value\" condition is added to the query.\n\n</td></tr><tr><td>\n\nvalue\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional - must also specify a field parameter. Value to search for in the specified field parameter.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how query the Knowledge Feedback \\[kb\\_feedback\\] table and list KB articles with comments that include Excel.\n\n```\nvar rec = new GlideRecord('kb_feedback');\nrec.addQuery('comments', 'CONTAINS', 'Excel');\nrec._query();\nwhile (rec.next()) { \n gs.info(rec.getDisplayValue('article') + \" comment: \" + rec.getValue('comments'));\n}\n```\n\nOutput:\n\n```\nKB0000005 comment: \n\t     Can you please add the version of Excel this applies to? All?\n\t\t\nKB0000005 comment: \n\t     Does this work for all Excel versions? OSX and Windows alike?\n```\n\n## Scoped GlideRecord - setAbortAction\\(Boolean b\\)\n\nSets a flag to indicate if the next database action \\(insert, update, delete\\) is to be aborted. This is often used in business rules.\n\nUse in an `onBefore` business rule to prevent the database action from being done. The business rule continues to run after setAbortAction\\(\\) is called. Calling setAbortAction\\(\\) does not stop subsequent business rules from executing. Calling this method only prevents the database action from occurring.\n\n|Name|Type|Description|\n|----|----|-----------|\n|b|Boolean|True to abort the next action. False if the action is to be allowed.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\n// Often used in business rule to check whether the current operation should be aborted.\nif (current.size > 16) {\n  current.setAbortAction(true);\n}\n```\n\n## Scoped GlideRecord - setCategory\\(String category\\)\n\nSets the query category, which determines how the query is routed to a secondary database.\n\nThis method requires the Secondary Database Pools \\[com.glide.secondary\\_db\\_pools\\] plugin. Call this method to route queries to a secondary \\(read replica\\) database based on the specified category, reducing load on the primary database. Due to replication lag, execution of a query on a read replica database may return slightly out of date results compared to executing the same query on the primary database.\n\nModifications to data are always serviced by the primary database, even if setCategory\\(\\) is used in the query. For example, a call to GlideRecord.update\\(\\) is always directed to the primary database even if the GlideRecord object has been provided with the name of a secondary database category via setCategory\\(\\).\n\nFor more information, see [KB0824441 Introduction to ServiceNow Read Replica Databases](https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0824441).\n\n<table id=\"table_bns_y1r_cjc\" 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\ncategory\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the category to use to route the query to a secondary database.Table: Secondary Database Categories \\[sys\\_db\\_category\\]\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThis example uses the `embedded_list` category to route the query to a secondary database.\n\n```\nvar gr = new GlideRecord('task');\ngr.setCategory('embedded_list');\ngr.query();\n```\n\n## Scoped GlideRecord - setLimit\\(Number maxNumRecords\\)\n\nSets the limit for number of records are fetched by the GlideRecord query.\n\n-   **Using setLimit\\(\\) with chooseWindow\\(\\)**\n\n    The setLimit\\(\\) method implicitly calls the chooseWindow\\(\\) method and might cause unexpected results when used with chooseWindow\\(\\) in a query.\n\n    -   If the chooseWindow\\(\\) method is called first, its record window is overwritten by the setLimit\\(\\) method.\n\n        Using the following lines in a query returns 100 records starting at row 1:\n\n        ```\n        grIncident.chooseWindow(20,30);\n        grIncident.setLimit(100);\n        ```\n\n    -   If the setLimit\\(\\) method is called first, the window set by chooseWindow\\(\\) is used and the limit is overwritten.\n\n        Using the following lines in a query returns 10 records starting at row 21:\n\n        ```\n        grIncident.setLimit(5);\n        grIncident.chooseWindow(20,30);\n        ```\n\n        **Note:** Running query\\(\\) with the chooseWindow\\(\\) method triggers a `COUNT(*)` query, which can result in slow performance on tables with a large number of records. You can use setLimit\\(\\) before chooseWindow\\(\\) to skip running the `COUNT(*)` query, but the same performance benefit is achievable using setNoCount\\(\\).\n\n\nSee also:\n\n-   [chooseWindow\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [query\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [setNoCount\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|maxNumRecords|Number|The maximum number of records to fetch.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar now_GR = new GlideRecord('incident');\nnow_GR.orderByDesc('sys_created_on');\nnow_GR.setLimit(10);\nnow_GR.query(); // this retrieves latest 10 incident records created\n```\n\n## Scoped GlideRecord - setNewGuidValue\\(String guid\\)\n\nSets the sys\\_id value for the current record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|guid|String|GUID to assign to the current record.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar now_GR = new GlideRecord('incident');\nnow_GR.setValue('short_description', 'The third floor printer is broken');\nnow_GR.setNewGuidValue('eb4636ca6f6d31005be8883e6b3ee333');\nnow_GR.insert();\ngs.info(now_GR.getValue('sys_id'));\n```\n\n## Scoped GlideRecord - setNoCount\\(\\)\n\nStops a GlideRecord query from running a `COUNT(*)` query.\n\nRunning query\\(\\) with some methods trigger a `COUNT(*)` query, such as the chooseWindow\\(\\) and getRowCount\\(\\) methods. The `COUNT(*)` query might cause slow performance on tables with a million or more records. For more information, see the [Performance Improvement - Remove Pagination Count \\[KB0817996\\]](https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0817996) article in the Now Support Knowledge Base.\n\n**Note:** The setLimit\\(\\) method also stops a `COUNT(*)`. Using setNoCount\\(\\) is unnecessary if the setLimit\\(\\) method is included in the query.\n\nSee also:\n\n-   [chooseWindow\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [query\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following code example shows how to use setNoCount\\(\\) to skip the `COUNT(*)` query on a windowed query set using the chooseWindow\\(\\) method.\n\n```\nvar  grIncident = new GlideRecord('incident');\n\ngrIncident.chooseWindow(6915, 6920, true);\ngrIncident.setNoCount();\ngrIncident.query();\n\nwhile (grIncident.next()) { // Iterate through the returned records\n    gs.info('Incident Number: ' + grIncident.number + ', Short Description: ' + grIncident.short_description);\n};\n```\n\nOutput:\n\n```\nIncident Number: INC0006811, Short Description: Request an account to be created for Fidelity 401(k) Plans\nIncident Number: INC0006918, Short Description: Please grant me additional roles in Oracle Fin Collections\nIncident Number: INC0006812, Short Description: Taxware Value-added Tax crashes when I try to launch it\nIncident Number: INC0006919, Short Description: Unable to Access SuccessFactors Learning\nIncident Number: INC0010004, Short Description: Incident for assessment not generating\n```\n\n## Scoped GlideRecord - setValue\\(String name, Object value\\)\n\nSets the value of the field with the specified name to the specified value.\n\nNormally the script does a `now_GR.category = value`. However, if the element name is itself a variable then you can use `now_GR.setValue(elementName, value)`. When setting a value, ensure the data type of the field matches the data type of the value you enter. For information about the differences between using setValue\\(\\) and direct assignment, see [Explanation of Assignment Behavior for Reference GlideList Fields \\[KB2557324\\]](https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB2557324) in the Now Support Knowledge Base.\n\n**Note:** If the Field Encryption Enterprise plugin is enabled and the instance has access to the key, this method can insert encrypted data into encrypted fields. If the instance does not have access to the key, this method returns an error. For more information, see [Platform Encryption](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/encryption-landing.md).\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|name|String|Name of the field.|\n|value|Object|Value to assign to the field.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar elementName = 'short_description'; \nvar now_GR = new GlideRecord('incident'); \nnow_GR.initialize(); \nnow_GR.setValue(elementName, \"My DB is not working\");\nnow_GR.insert();\n```\n\n## Scoped GlideRecord - setWorkflow\\(Boolean enable\\)\n\nEnables or disables running business rules, script engines, or audits.\n\n**Note:** The setWorkflow\\(\\) method is ignored when subsequently using either the deleteProblem\\(\\) or deleteMultiple\\(\\) methods to cascade delete.\n\n**Warning:** Disabling the running of business rules, script engines, and audit can have a significant impact on your ServiceNow® instance and how it operates. Ensure that you thoroughly test this change before deploying it to production.\n\n**Note:** This method can't be set for cross-scoped applications. For additional information, see the following KB article [https://support.servicenow.com/kb?id=kb\\_article\\_view&amp;sysparm\\_article=KB0820691](https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0820691).\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\nenable\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether to enable or disable the running of business rules, script engines, and audit.Valid values:\n\n-   true: Enables running business rules, script engines, or audits.\n-   false: Disables running business rules, script engines, or audits.\n\nDefault: true\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\n```\n//Enable business rules, scripts engines for x_app_table\nvar now_GR = new GlideRecord(\"x_app_table\"); \nnow_GR.setWorkflow(true);\n```\n\n## Scoped GlideRecord - update\\(String reason\\)\n\nUpdates the GlideRecord with any changes that have been made. If the record does not already exist, it is inserted.\n\n|Name|Type|Description|\n|----|----|-----------|\n|reason|String|Optional. Reason for the update. The reason appears in the audit record.|\n\n|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the new or updated record. Returns null if the update fails.|\n\nThe following example shows how to update the Short Description field of an incident.\n\n```\nvar now_GR = new GlideRecord('incident');\nnow_GR.get('99ebb4156fa831005be8883e6b3ee4b9');\nnow_GR.setValue('short_description', 'Update the short description');\nnow_GR.update();\ngs.info(now_GR.getElement('short_description'));\n```\n\nOutput:\n\n```\nUpdate the short description.\n```\n\n## Scoped GlideRecord - updateMultiple\\(\\)\n\nUpdates each GlideRecord in a stated query with a specified set of changes.\n\nThis method does not support adding multiple journal entries.\n\nThe **glide.db.forced.chunk.threshold** system property sets the threshold above which forces chunk record deletions and updates. Chunking helps to prevent non-primary key deletions on huge tables from causing replication problems. For more information, see [Available system properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_AvailableSystemProperties.md).\n\n**Note:** To ensure expected results, use the setValue\\(\\) method instead of direct assignments. That is, use `gr_Now.setValue('<field_name>', '4'));` instead of `gr_Now.<field_name> = 4`.\n\n**Note:** Do not use this method with the chooseWindow\\(\\) or setLimit\\(\\) methods when working with large tables.\n\nThis method sets new values and does not clear existing values. To clear an existing value, use the setValue\\(\\) method and set the field to 'NULL'. For more information, see [Setting a GlideRecord variable to 'NULL'](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/r_SettingAGlideRecordVariableToNull.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to update the state of all active incidents to 4 - \"Awaiting User Info\".\n\n```\nvar now_GR = new GlideRecord('incident');\nnow_GR.addQuery('active', true);\nnow_GR.setValue('state',  4);\nnow_GR.updateMultiple();\n```\n\nThis example shows how to clear existing values of the description field for priority 1 incidents.\n\n```\nvar test = new GlideRecord('incident');\ntest.addEncodedQuery('priority=1');\ntest.query();\n \ntest.setValue('description','NULL');\ntest.updateMultiple();\n```\n\n## Scoped GlideRecord - updateWithReferences\\(Object reason\\)\n\nUpdates a record and also inserts or updates any related records with the information provided.\n\n|Name|Type|Description|\n|----|----|-----------|\n|reason|Object|Reason for the updates. The reason is displayed in the audit record.|\n\n|Type|Description|\n|----|-----------|\n|String|The sys\\_id for the record being updated.|\n\nIf processing an incident where the Caller ID is set to reference sys\\_user record 'John Doe,' then the following code would update John Doe's user record. If processing an incident where there's no caller ID specified, then the following code creates a new sys\\_user record with the provided information \\(first\\_name, last\\_name\\) and sets the caller ID value to the newly created sys\\_user record.\n\n```\nvar inc = new GlideRecord('incident');\ninc.get(inc_sys_id);  // Looking up an existing incident record where 'inc_sys_id' represents the sys_id of a incident record\ninc.caller_id.first_name = 'John';\ninc.caller_id.last_name = 'Doe';\ninc.updateWithReferences();\n}\n```\n\n"}}