---
sourceDocument: Zurich API Reference
sourceDocumentLink: https://www.servicenow.com/docs/r/zurich/api-reference

 Release :

    - zurich

ft:locale :

    - en-US

ft:publication_title :

    - Zurich API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideRecord - Scoped

# GlideRecord - Scoped {#ariaid-title1}

* Release version: Zurich
* 
* Updated July 31, 2025
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 58 minutes to read

The scoped GlideRecord API is used for database operations.
The 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.

See 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.

For information on a class that performs the same functions as
GlideRecord and enforces ACLs, see [Using GlideRecordSecure](https://www.servicenow.com/docs/1DG2puD64e_Jpggk_TuPZw#p_GlideServerAPIs "ServiceNow provides APIs for the Glide Server.").

Always 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.

You 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://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US).

## Retrieve values from records {#c_GlideRecordScopedAPI__id_tvw_lbc_npb}

In 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.{#c_GlideRecordScopedAPI__gr-api-dot-walk-recommendations-p1}

Instead of retrieving the entire object, you can
use one of the following methods to copy the field values:{#c_GlideRecordScopedAPI__gr-api-dot-walk-recommendations-p2}

* [getValue()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordGetValue_String "Retrieves the string value of an underlying element in a field.")
* [getDisplayValue()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordGetDisplayValue "Retrieves the display value for the current record.")

{#c_GlideRecordScopedAPI__gr-api-dot-walk-recommendation-lnx}  
If 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:

    var mgr = current.caller_id.manager.toString();

See also:

* [GlideAggregate](https://www.servicenow.com/docs/QWkkDv0bsvqUeYStHWuhbg#c_GlideAggregateScopedAPI "The GlideAggregate API enables creating database aggregation queries.")
* [GlideElement](https://www.servicenow.com/docs/n4FSgCkxOii7rIaF5cOhDg#c_GlideElementScopedAPI "The scoped GlideElement API provides a number of convenient script methods for dealing with fields and their values. Scoped GlideElement methods are available for the fields of the current glide record.")
* [GlideQuery](https://www.servicenow.com/docs/zTF54acHaiNEOuN28cn_9A#GlideQueryGlobalAPI "The GlideQuery script include is an alternative to the GlideRecord API for performing CRUD operations on record data from server-side scripts.")
{#c_GlideRecordScopedAPI__ul_mky_nkd_npb}

## Scoped GlideRecord - addActiveQuery() {#ariaid-title2}

Adds a filter to return active records.
{#SGR-addActiveQuery__table_n2r_tdq_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#SGR-addActiveQuery__table_n2r_tdq_fz} {#SGR-addActiveQuery__table_o2r_tdq_fz__entry__2}

| Type | Description |
|-|-|
| GlideQueryCondition | Filter to return active records. |
[Table 2. Returns]

{#SGR-addActiveQuery__table_o2r_tdq_fz}  

    var inc = new GlideRecord('incident');
    inc.addActiveQuery();
    inc.query();

## Scoped GlideRecord - addEncodedQuery(String query, Boolean enforceFieldACL) {#ariaid-title3}

Adds an encoded query to other queries that may have been set.
Always 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.

You 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://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US).  
Note:  
To enforce query access based on the user, use [addUserEncodedQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserEncodedQuery_S "Adds a query using an encoded query string. Use this method to enforce query access based on the user.").
{#r_ScopedGlideRecordAddEncodedQuery_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| query | String | An [encoded query string](https://www.servicenow.com/docs/access?context=c_EncodedQueryStrings&version=zurich&pubname=zurich-platform-user-interface&ft:locale=en-US). |
| enforceFieldACL | Boolean | Optional. Flag that indicates whether to enforce field ACL (Access Control List) rules. Valid values: * true: Enforce field ACLs. * false: Don't enforce field ACLs. Default: false |
[Table 3. Parameters]

{#r_ScopedGlideRecordAddEncodedQuery_String__table_vy2_525_jq} {#r_ScopedGlideRecordAddEncodedQuery_String__table_up3_d5b_2r__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 4. Returns]

{#r_ScopedGlideRecordAddEncodedQuery_String__table_up3_d5b_2r}  

    var queryString = "priority=1^ORpriority=2";
    var now_GR = new GlideRecord('incident');
    now_GR.addEncodedQuery(queryString);
    now_GR.query();
    while (now_GR.next()) {
      gs.addInfoMessage(now_GR.getValue('number'));
    }

## Scoped GlideRecord - addFunction(Object function) {#ariaid-title4}

Applies a pre-defined GlideDBFunctionBuilder object to a record.
Use 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.
{#r_ScopedGlideRecordAddFunction_O__table_mkh_dnk_kbb__entry__3}

| Name | Type | Description |
|-|-|-|
| function | Object | GlideDBFunctionBuilder object that defines a SQL operation. |
[Table 5. Parameters]

{#r_ScopedGlideRecordAddFunction_O__table_mkh_dnk_kbb} {#r_ScopedGlideRecordAddFunction_O__table_nkh_dnk_kbb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 6. Returns]

{#r_ScopedGlideRecordAddFunction_O__table_nkh_dnk_kbb}  

    var functionBuilder = new GlideDBFunctionBuilder();
    var myAddingFunction = functionBuilder.add();
    myAddingFunction = functionBuilder.field('order');
    myAddingFunction = functionBuilder.field('priority');
    myAddingFunction = functionBuilder.build();

    // Query incidents in which order + priority is less than 5 and display that added value
    var now_GR = new GlideRecord('incident');
    now_GR.addFunction(myAddingFunction);
    now_GR.addQuery(myAddingFunction, '<', 5);
    now_GR.query();
    while(now_GR.next())
      gs.info(now_GR.getValue(myAddingFunction));

Output:

    1
    4
    3
    1
    1
    2
    1

## Scoped GlideRecord -- addJoinQuery(String joinTable, String primaryField, String
joinTableField) {#ariaid-title5}

Adds a filter to return records based on a relationship in a table related to the
current GlideRecord.
You 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.

This 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.)

Always 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.

You 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://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US).
{#r_ScopedGlideRecordAddJoinQuery_String_Object_Object__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| joinTable | String | Name of table to use in the join, such as 'incident'. |
| primaryField | String | Optional. Name of the field in the GlideRecord to use to join the field specified in the joinTableField parameter. Default: sys_id |
| joinTableField | String | Optional. 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. |
[Table 7. Parameters]

{#r_ScopedGlideRecordAddJoinQuery_String_Object_Object__table_vy2_525_jq} {#r_ScopedGlideRecordAddJoinQuery_String_Object_Object__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| GlideQueryCondition | Filter that lists records where the relationships match. |
[Table 8. Returns]

{#r_ScopedGlideRecordAddJoinQuery_String_Object_Object__table_qpt_3f5_jq}  
Find 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.

    var prob = new GlideRecord('problem');
    prob.addJoinQuery('incident');
    prob.query();

Find inactive problems with associated incidents.

    // Look for Problem records that have associated Incident records
    var now_GR = new GlideRecord('problem');
    var grSQ = now_GR.addJoinQuery('incident');
     
    // Where the Problem records are "active=false"
    now_GR.addQuery('active', 'false');
     
    // And the Incident records are "active=true"
    grSQ.addCondition('active', 'true');
     
    // Query
    now_GR.query();
     
    // Iterate and output results
    while (now_GR.next()) {
    gs.info(now_GR.getValue('number'));
    }

Find problems that have incidents associated where the incident
caller_id field value matches that of the problem
opened_by field.

    var now_GR = new GlideRecord('problem'); 
            now_GR.addJoinQuery('incident', 'opened_by', 'caller_id'); 
            now_GR.query();

## Scoped GlideRecord - addNotNullQuery(String fieldName) {#ariaid-title6}

A filter that specifies records where the value of the field passed in the parameter is
not null.
Always 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.

You 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://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US).
{#r_ScopedGlideRecordAddNotNullQuery_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| fieldName | String | The name of the field to be checked. |
[Table 9. Parameters]

{#r_ScopedGlideRecordAddNotNullQuery_String__table_vy2_525_jq} {#r_ScopedGlideRecordAddNotNullQuery_String__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| GlideQueryCondition | A filter that specifies records where the value of the field passed in the parameter is not null. |
[Table 10. Returns]

{#r_ScopedGlideRecordAddNotNullQuery_String__table_qpt_3f5_jq}  

    var target = new GlideRecord('incident'); 
    target.addNotNullQuery('short_description');
    target.query();   // Issue the query to the database to get all records where short_description is not null
    while (target.next()) {   
         // add code here to process the incident record
    }

## Scoped GlideRecord - addNullQuery(String fieldName) {#ariaid-title7}

Adds a filter to return records where the value of the specified field is
null.
Always 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.

You 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://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US).
{#r_ScopedGlideRecordAddNullQuery_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| fieldName | String | The name of the field to be checked. |
[Table 11. Parameters]

{#r_ScopedGlideRecordAddNullQuery_String__table_vy2_525_jq} {#r_ScopedGlideRecordAddNullQuery_String__table_sp2_b5b_2r__entry__2}

| Type | Description |
|-|-|
| GlideQueryCondition | The query condition added to the GlideRecord. |
[Table 12. Returns]

{#r_ScopedGlideRecordAddNullQuery_String__table_sp2_b5b_2r}  

    var target = new GlideRecord('incident'); 
    target.addNullQuery('short_description');
    target.query();   // Issue the query to the database to get all records where short_description is null
    while (target.next()) {   
       // add code here to process the incident record
    }

## Scoped GlideRecord - addQuery(String name, Object value) {#ariaid-title8}

Build a search query and return the rows that match the request.
If 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://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#r_ScopedGlideQueryConditionAddOrCondition "Appends a two-or-three parameter OR condition to an existing GlideQueryCondition.").  
Note:  
To enforce query access based on the user, use [addUserQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserQuery_S_O_O "Provides 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.").

When 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".

Always 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.

You 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://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US).
{#r_ScopedGlideRecordAddQuery_String_Object__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Name 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://www.servicenow.com/docs/access?context=configure-single-table-for-indexing&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US). * 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://www.servicenow.com/docs/access?context=index-multiple-tables&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US). {#r_ScopedGlideRecordAddQuery_String_Object__ul_e5c_slk_xhb} Note: For more details on the use of the reserved names, see [Querying tables in script](https://www.servicenow.com/docs/Y~nD1FOgoLqUiVUAWKq6_w#c_UsingGlideRecordToQueryTables "Using methods in the GlideRecord API, you can return all records from a table, return records from a table that satisfy specific conditions, or return records that include a string from a single table or from multiple tables in a text index group."). |
| value | Object | Value on which to query (not case-sensitive). |
[Table 13. Parameters]

{#r_ScopedGlideRecordAddQuery_String_Object__table_vy2_525_jq} {#r_ScopedGlideRecordAddQuery_String_Object__table_pd3_ytb_2r__entry__2}

| Type | Description |
|-|-|
| GlideQueryCondition | Query condition added to the GlideRecord. |
[Table 14. Returns]

{#r_ScopedGlideRecordAddQuery_String_Object__table_pd3_ytb_2r}  
This code example shows how to query the active records in the incident table and then set
them all to inactive.

    var rec = new GlideRecord('incident');
    rec.addQuery('active', true);
    rec.query();
    while (rec.next()) {
      rec.setValue('active', false);
      rec.update();
    }

This 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.

    var now_GR = new GlideRecord("kb_knowledge);
    now_GR.addQuery("123TEXTQUERY321", "email server");
    now_GR.addQuery("123TEXTINDEXGROUP321", "portal");
    now_GR.query();

## Scoped GlideRecord - addQuery(String name, String operator, Object value) {#ariaid-title9}

Provides the ability to build a request, which when executed, returns the rows from the
specified table, that match the request.
If 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://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#r_ScopedGlideQueryConditionAddOrCondition "Appends a two-or-three parameter OR condition to an existing GlideQueryCondition.").

Always 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.

You 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://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US).  
Note:  
To enforce query access based on the user, use [addUserQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserQuery_S_O_O "Provides 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.").
{#r_ScopedGlideRecordAddQuery_String_String_Object__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Table field name. |
| operator | String | Query operator. The available values are dependent on the data type of the <var class="keyword varname">value</var> parameter. Numbers: * = * != * \> * \>= * \< * \<= {#r_ScopedGlideRecordAddQuery_String_String_Object__ul_qyb_rbt_3y} Strings (must be in upper case): * = * != * IN * NOT IN * STARTSWITH * ENDSWITH * CONTAINS * DOES NOT CONTAIN * INSTANCEOF {#r_ScopedGlideRecordAddQuery_String_String_Object__ul_egz_vbt_3y} Note: Use CONTAINS instead of the LIKE operator. |
| value | Object | Value on which to query (not case-sensitive). |
[Table 15. Parameters]

{#r_ScopedGlideRecordAddQuery_String_String_Object__table_vy2_525_jq} {#r_ScopedGlideRecordAddQuery_String_String_Object__table_gty_wtb_2r__entry__2}

| Type | Description |
|-|-|
| GlideQueryCondition | The query condition that was added to the GlideRecord. |
[Table 16. Returns]

{#r_ScopedGlideRecordAddQuery_String_String_Object__table_gty_wtb_2r}  

    var rec = new GlideRecord('incident');
    rec.addQuery('active',true);
    rec.addQuery('sys_created_on', ">", "2010-01-19 04:05:00");
    rec.query();
    while (rec.next()) {
      rec.setValue('active', false);
      gs.info('Active incident ' + rec.getValue('number') + ' closed');
      rec.update();
    }

Using the IN operator.

    var now_GR = new GlideRecord('incident');
    now_GR.addQuery('number','IN','INC00001,INC00002');
    now_GR.query();
    while(now_GR.next()) {
      //do something....
    }

## Scoped GlideRecord - addSystemEncodedQuery(String query) {#ariaid-title10}

Adds a query using an encoded query string. Use this method to bypass query access.
Use this method when system-level access is intended, so that query ACL enforcement is explicitly bypassed for the user. Use [addUserEncodedQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserEncodedQuery_S "Adds a query using an encoded query string. Use this method to enforce query access based on the user.")
to enforce query access.  
Additional methods for system-level access that bypass query ACL checks:

* [addSystemOrderBy()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemOrderBy_S "Specifies an orderBy column. Use this method to bypass query access.")
* [addSystemOrderByDesc()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemOrderByDesc_S "Specifies a descending orderBy column. Use this method to bypass query access.")
* [addSystemQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemQuery_S_O_O "Provides 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.")
* [GlideQueryCondition - addSystemCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addSystemCondition_S_S_O "Adds an AND condition to the current condition. Use this method to bypass query access.")
* [GlideQueryCondition - addSystemOrCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addSystemOrCondition_S_O_O "Appends a two-or-three parameter OR condition to an existing GlideQueryCondition. Use this method to bypass query access.")
{#SGR-addSystemEncodedQuery_S__ul_znd_wlp_53c}

For information on using this method with GlideRecordSecure, see [Enforcing query ACLs](https://www.servicenow.com/docs/1DG2puD64e_Jpggk_TuPZw#c_UsingGlideRecordSecure__enforcing_query_ACLs).

Always 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.

You 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://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US).
{#SGR-addSystemEncodedQuery_S__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| query | String | An [encoded query string](https://www.servicenow.com/docs/access?context=c_EncodedQueryStrings&version=zurich&pubname=zurich-platform-user-interface&ft:locale=en-US). |
[Table 17. Parameters]

{#SGR-addSystemEncodedQuery_S__table_vy2_525_jq} {#SGR-addSystemEncodedQuery_S__table_up3_d5b_2r__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 18. Returns]

{#SGR-addSystemEncodedQuery_S__table_up3_d5b_2r}  
The following example shows how to return the number value of the first 12 incidents with a priority value of 1 or 2.

    var queryString = "priority=1^ORpriority=2";
    var now_GR = new GlideRecord('incident');
    now_GR.addSystemEncodedQuery(queryString);

    now_GR.setLimit(12);
    now_GR.query();

    while (now_GR.next()) {
      gs.info(now_GR.getValue('number'));
    }

Output:

    *** Script: INC0002318
    *** Script: INC0000144
    *** Script: INC0006927
    *** Script: INC0003577
    *** Script: INC0006928
    *** Script: INC0000135
    *** Script: INC0005637
    *** Script: INC0003196
    *** Script: INC0002647
    *** Script: INC0004074
    *** Script: INC0003444
    *** Script: INC0001694

## Scoped GlideRecord - addSystemOrderBy(String name) {#ariaid-title11}

Specifies an orderBy column. Use this method to bypass query access.
Use this method when system-level access is intended, so that query ACL enforcement is explicitly bypassed for the user. Use [addUserOrderBy()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserOrderBy_S "Specifies an orderBy column. Use this method to enforce query access based on the user.")
to enforce query access.  
Additional methods for system-level access that bypass query ACL checks:

* [addSystemEncodedQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemEncodedQuery_S "Adds a query using an encoded query string. Use this method to bypass query access.")
* [addSystemQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemQuery_S_O_O "Provides 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.")
* [GlideQueryCondition - addSystemCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addSystemCondition_S_S_O "Adds an AND condition to the current condition. Use this method to bypass query access.")
* [GlideQueryCondition - addSystemOrCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addSystemOrCondition_S_O_O "Appends a two-or-three parameter OR condition to an existing GlideQueryCondition. Use this method to bypass query access.")
{#SGR-addSystemOrderBy_S__ul_znd_wlp_53c}

Call 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://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemOrderByDesc_S "Specifies a descending orderBy column. Use this method to bypass query access.").
{#SGR-addSystemOrderBy_S__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Column name to use to order the records in this GlideRecord object. |
[Table 19. Parameters]

{#SGR-addSystemOrderBy_S__table_vy2_525_jq} {#SGR-addSystemOrderBy_S__table_ts3_ktb_2r__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 20. Returns]

{#SGR-addSystemOrderBy_S__table_ts3_ktb_2r}  
The following example shows how to order incident records in ascending order by Short Description.

    var queryString = "priority=1";
    var now_GR = new GlideRecord('incident');

    now_GR.addSystemOrderBy('short_description'); // Ascending Order
    now_GR.addSystemEncodedQuery(queryString);

    now_GR.setLimit(6);
    now_GR.query();

    while (now_GR.next()) {
      gs.info(now_GR.getValue('short_description'));
    }

Output:

    *** Script: Access token revoked
    *** Script: Access token revoked
    *** Script: Account locked, pls reset my password for Linkedin Sales Navigator
    *** Script: Active Directory (AD) synchronization error
    *** Script: Adobe Photoshop & Digital Publishing Instance is down
    *** Script: Application response time is poor when performing any action in ADP Payroll S...

## Scoped GlideRecord - addSystemOrderByDesc(String name) {#ariaid-title12}

Specifies a descending orderBy column. Use this method to bypass query access.
Use this method when system-level access is intended, so that query ACL enforcement is explicitly bypassed for the user. Use [addUserOrderByDesc()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserOrderByDesc_S "Specifies a descending orderBy column. Use this method to enforce query access based on the user.")
to enforce query access.  
Additional methods for system-level access that bypass query ACL checks:

* [addSystemEncodedQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemEncodedQuery_S "Adds a query using an encoded query string. Use this method to bypass query access.")
* [addSystemQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemQuery_S_O_O "Provides 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.")
* [GlideQueryCondition - addSystemCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addSystemCondition_S_S_O "Adds an AND condition to the current condition. Use this method to bypass query access.")
* [GlideQueryCondition - addSystemOrCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addSystemOrCondition_S_O_O "Appends a two-or-three parameter OR condition to an existing GlideQueryCondition. Use this method to bypass query access.")
{#SGR-addSystemOrderByDesc_S__ul_znd_wlp_53c}

Call 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://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemOrderBy_S "Specifies an orderBy column. Use this method to bypass query access.").
{#SGR-addSystemOrderByDesc_S__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Column name to use to order the records in a GlideRecord object. |
[Table 21. Parameters]

{#SGR-addSystemOrderByDesc_S__table_vy2_525_jq} {#SGR-addSystemOrderByDesc_S__table_lpd_ktb_2r__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 22. Returns]

{#SGR-addSystemOrderByDesc_S__table_lpd_ktb_2r}  
The following example shows how to order incident records in descending order by Short Description.

    var queryString = "priority=2";
    var now_GR = new GlideRecord('incident');

    now_GR.addSystemOrderByDesc('short_description'); //Descending Order
    now_GR.addSystemEncodedQuery(queryString);

    now_GR.setLimit(6);
    now_GR.query();

    while (now_GR.next()) {
      gs.info(now_GR.getValue('short_description'));
    }

Output:

    *** Script: Xignite U.S. and Global Real Time Quotes upgrade to the latest version
    *** Script: Xignite Company, Market and Industry News Headlines upgrade to the latest ver...
    *** Script: Workday Talent Management Instance relocation from US datacenter to Hongkong ...
    *** Script: Warning displayed while launching Tableau Server
    *** Script: Warning displayed while launching SAP Financial Accounting
    *** Script: Warning displayed while launching Jive Daily

## Scoped GlideRecord - addSystemQuery(String name, Object operator, Object value) {#ariaid-title13}

Provides 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.
Use this method when system-level access is intended, so that query ACL enforcement is explicitly bypassed for the user. Use [addUserQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserQuery_S_O_O "Provides 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.")
to enforce query access.  
Additional methods for system-level access that bypass query ACL checks:

* [addSystemEncodedQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemEncodedQuery_S "Adds a query using an encoded query string. Use this method to bypass query access.")
* [addSystemOrderBy()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemOrderBy_S "Specifies an orderBy column. Use this method to bypass query access.")
* [addSystemOrderByDesc()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemOrderByDesc_S "Specifies a descending orderBy column. Use this method to bypass query access.")
* [GlideQueryCondition - addSystemCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addSystemCondition_S_S_O "Adds an AND condition to the current condition. Use this method to bypass query access.")
* [GlideQueryCondition - addSystemOrCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addSystemOrCondition_S_O_O "Appends a two-or-three parameter OR condition to an existing GlideQueryCondition. Use this method to bypass query access.")
{#SGR-addSystemQuery_S_O_O__ul_znd_wlp_53c}

Always 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.

You 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://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US).
{#SGR-addSystemQuery_S_O_O__table_ix2_hvp_dt__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Table field name. |
| operator | Object | Query operator. The available values are dependent on the data type of the <var class="keyword varname">value</var> parameter. Numbers: * = * != * \> * \>= * \< * \<= {#SGR-addSystemQuery_S_O_O__ul_qyb_rbt_3y} Strings (must be in upper case): * = * != * IN * NOT IN * STARTSWITH * ENDSWITH * CONTAINS * DOES NOT CONTAIN * INSTANCEOF {#SGR-addSystemQuery_S_O_O__ul_egz_vbt_3y} Note: Use CONTAINS instead of the LIKE operator. Dynamic schema operators: * = * != * \< * \> * \<= * \>= * BETWEEN * CONTAINS * DOES_NOT_CONTAIN * ENDSWITH * GT_FIELD * GT_OR_EQUALS_FIELD * IN * ISEMPTY * ISNOTEMPTY * IS_NOT_NULL * IS_NULL * LIKE * LT_FIELD * LT_OR_EQUALS_FIELD * MATCHES * NOT_IN * NOT_LIKE * NOT_MATCHES * NSAMEAS * SAMEAS * STARTSWITH {#SGR-addSystemQuery_S_O_O__ul_g5t_j32_cgc} |
| value | Object | Value on which to query (not case-sensitive). |
[Table 23. Parameters]

{#SGR-addSystemQuery_S_O_O__table_ix2_hvp_dt} {#SGR-addSystemQuery_S_O_O__table_gty_wtb_2r__entry__2}

| Type | Description |
|-|-|
| [GlideQueryCondition](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#c_GlideQueryConditionScopedAPI "The scoped GlideQueryCondition API provides additional AND or OR conditions that can be added to the current condition, allowing you to build complex queries.") | The query condition that was added to the GlideRecord. |
[Table 24. Returns]

{#SGR-addSystemQuery_S_O_O__table_gty_wtb_2r}  
The following example shows how to explicitly return all active users named Fred.

    var rec = new GlideRecord('sys_user');
    rec.addSystemQuery("first_name", "=", "Fred");
    rec.query();

    while (rec.next()) {
      gs.info('Active user ' + rec.getValue('last_name'));
    }

Output:

    Active user Luddy
    Active user Kunde

## Scoped GlideRecord - addUserEncodedQuery(String query) {#ariaid-title14}

Adds a query using an encoded query string. Use this method to enforce query access based on the user.
This method returns only records that the current user has query access to (based on ACLs).  
Related methods:

* [addEncodedQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordAddEncodedQuery_String "Adds an encoded query to other queries that may have been set.") provides the same functionality without ACL enforcement.
* [addSystemEncodedQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemEncodedQuery_S "Adds a query using an encoded query string. Use this method to bypass query access.") bypasses query access checks.
{#SGR-addUserEncodedQuery_S__ul_i2h_csq_53c}  
Additional methods for enforcing query ACL checks:

* [addUserOrderBy()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserOrderBy_S "Specifies an orderBy column. Use this method to enforce query access based on the user.")
* [addUserOrderByDesc()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserOrderByDesc_S "Specifies a descending orderBy column. Use this method to enforce query access based on the user.")
* [addUserQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserQuery_S_O_O "Provides 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.")
* [GlideQueryCondition - addUserCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addUserCondition_S_S_O "Adds an AND condition to the current condition. Use this method to enforce query access based on the user.")
* [GlideQueryCondition - addUserOrCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addUserOrCondition_S_O_O "Appends a two-or-three parameter OR condition to an existing GlideQueryCondition. Use this method to enforce query access based on the user.")
{#SGR-addUserEncodedQuery_S__ul_znd_wlp_53c}

For information on using this method with GlideRecordSecure, see [Enforcing query ACLs](https://www.servicenow.com/docs/1DG2puD64e_Jpggk_TuPZw#c_UsingGlideRecordSecure__enforcing_query_ACLs).

Always 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.

You 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://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US).
{#SGR-addUserEncodedQuery_S__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| query | String | An [encoded query string](https://www.servicenow.com/docs/access?context=c_EncodedQueryStrings&version=zurich&pubname=zurich-platform-user-interface&ft:locale=en-US). |
[Table 25. Parameters]

{#SGR-addUserEncodedQuery_S__table_vy2_525_jq} {#SGR-addUserEncodedQuery_S__table_up3_d5b_2r__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 26. Returns]

{#SGR-addUserEncodedQuery_S__table_up3_d5b_2r}  
The following example shows how to return the number value of the first 12 incidents with a priority value of 1 or 2.

    var queryString = "priority=1^ORpriority=2";
    var now_GR = new GlideRecord('incident');
    now_GR.addUserEncodedQuery(queryString);

    now_GR.setLimit(12);
    now_GR.query();

    while (now_GR.next()) {
      gs.info(now_GR.getValue('number'));
    }

Output:

    *** Script: INC0002318
    *** Script: INC0000144
    *** Script: INC0006927
    *** Script: INC0003577
    *** Script: INC0006928
    *** Script: INC0000135
    *** Script: INC0005637
    *** Script: INC0003196
    *** Script: INC0002647
    *** Script: INC0004074
    *** Script: INC0003444
    *** Script: INC0001694

## Scoped GlideRecord - addUserOrderBy(String name) {#ariaid-title15}

Specifies an orderBy column. Use this method to enforce query access based on the user.
This method returns only records that the current user has query access to (based on ACLs).  
Related methods:

* [orderBy()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordOrderBy_String "Specifies an orderBy column.") provides the same functionality without ACL enforcement.
* [addSystemOrderBy()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemOrderBy_S "Specifies an orderBy column. Use this method to bypass query access.") bypasses query access checks.
{#SGR-addUserOrderBy_S__ul_i2h_csq_53c}  
Additional methods for enforcing query ACL checks:

* [addUserEncodedQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserEncodedQuery_S "Adds a query using an encoded query string. Use this method to enforce query access based on the user.")
* [addUserQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserQuery_S_O_O "Provides 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.")
* [GlideQueryCondition - addUserCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addUserCondition_S_S_O "Adds an AND condition to the current condition. Use this method to enforce query access based on the user.")
* [GlideQueryCondition - addUserOrCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addUserOrCondition_S_O_O "Appends a two-or-three parameter OR condition to an existing GlideQueryCondition. Use this method to enforce query access based on the user.")
{#SGR-addUserOrderBy_S__ul_znd_wlp_53c}

Call 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://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserOrderByDesc_S "Specifies a descending orderBy column. Use this method to enforce query access based on the user.").
{#SGR-addUserOrderBy_S__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Column name to use to order the records in this GlideRecord object. |
[Table 27. Parameters]

{#SGR-addUserOrderBy_S__table_vy2_525_jq} {#SGR-addUserOrderBy_S__table_ts3_ktb_2r__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 28. Returns]

{#SGR-addUserOrderBy_S__table_ts3_ktb_2r}  
The following example shows how to order incident records in ascending order by Short Description.

    var queryString = "priority=1";
    var now_GR = new GlideRecord('incident');

    now_GR.addUserOrderBy('short_description'); // Ascending Order
    now_GR.addUserEncodedQuery(queryString);

    now_GR.setLimit(6);
    now_GR.query();

    while (now_GR.next()) {
      gs.info(now_GR.getValue('short_description'));
    }

Output:

    *** Script: Access token revoked
    *** Script: Access token revoked
    *** Script: Account locked, pls reset my password for Linkedin Sales Navigator
    *** Script: Active Directory (AD) synchronization error
    *** Script: Adobe Photoshop & Digital Publishing Instance is down
    *** Script: Application response time is poor when performing any action in ADP Payroll S...

## Scoped GlideRecord - addUserOrderByDesc(String name) {#ariaid-title16}

Specifies a descending orderBy column. Use this method to enforce query access based on the user.
This method returns only records that the current user has query access to (based on ACLs).  
Related methods:

* [orderByDesc()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordOrderByDesc_String "Specifies a descending orderBy column.") provides the same functionality without ACL enforcement.
* [addSystemOrderByDesc()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemOrderByDesc_S "Specifies a descending orderBy column. Use this method to bypass query access.") bypasses query access checks.
{#SGR-addUserOrderByDesc_S__ul_i2h_csq_53c}  
Additional methods for enforcing query ACL checks:

* [addUserEncodedQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserEncodedQuery_S "Adds a query using an encoded query string. Use this method to enforce query access based on the user.")
* [addUserQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserQuery_S_O_O "Provides 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.")
* [GlideQueryCondition - addUserCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addUserCondition_S_S_O "Adds an AND condition to the current condition. Use this method to enforce query access based on the user.")
* [GlideQueryCondition - addUserOrCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addUserOrCondition_S_O_O "Appends a two-or-three parameter OR condition to an existing GlideQueryCondition. Use this method to enforce query access based on the user.")
{#SGR-addUserOrderByDesc_S__ul_znd_wlp_53c}

Call 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://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserOrderBy_S "Specifies an orderBy column. Use this method to enforce query access based on the user.").
{#SGR-addUserOrderByDesc_S__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Column name to use to order the records in a GlideRecord object. |
[Table 29. Parameters]

{#SGR-addUserOrderByDesc_S__table_vy2_525_jq} {#SGR-addUserOrderByDesc_S__table_lpd_ktb_2r__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 30. Returns]

{#SGR-addUserOrderByDesc_S__table_lpd_ktb_2r}  
The following example shows how to order incident records in descending order by Short Description.

    var queryString = "priority=2";
    var now_GR = new GlideRecord('incident');

    now_GR.addUserOrderByDesc('short_description'); //Descending Order
    now_GR.addUserEncodedQuery(queryString);

    now_GR.setLimit(6);
    now_GR.query();

    while (now_GR.next()) {
      gs.info(now_GR.getValue('short_description'));
    }

Output:

    *** Script: Xignite U.S. and Global Real Time Quotes upgrade to the latest version
    *** Script: Xignite Company, Market and Industry News Headlines upgrade to the latest ver...
    *** Script: Workday Talent Management Instance relocation from US datacenter to Hongkong ...
    *** Script: Warning displayed while launching Tableau Server
    *** Script: Warning displayed while launching SAP Financial Accounting
    *** Script: Warning displayed while launching Jive Daily

## Scoped GlideRecord - addUserQuery(String name, Object operator, Object value) {#ariaid-title17}

Provides 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.
This method returns only records that the current user has query access to (based on ACLs).  
Related methods:

* [addQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordAddQuery_String_String_Object "Provides the ability to build a request, which when executed, returns the rows from the specified table, that match the request.") provides the same functionality without ACL enforcement.
* [addSystemQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addSystemQuery_S_O_O "Provides 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.") bypasses query access checks.
{#SGR-addUserQuery_S_O_O__ul_i2h_csq_53c}  
Additional methods for enforcing query ACL checks:

* [addUserOrderBy()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserOrderBy_S "Specifies an orderBy column. Use this method to enforce query access based on the user.")
* [addUserEncodedQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserEncodedQuery_S "Adds a query using an encoded query string. Use this method to enforce query access based on the user.")
* [addUserOrderByDesc()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserOrderByDesc_S "Specifies a descending orderBy column. Use this method to enforce query access based on the user.")
* [GlideQueryCondition - addUserCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addUserCondition_S_S_O "Adds an AND condition to the current condition. Use this method to enforce query access based on the user.")
* [GlideQueryCondition - addUserOrCondition()](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#SGQC-addUserOrCondition_S_O_O "Appends a two-or-three parameter OR condition to an existing GlideQueryCondition. Use this method to enforce query access based on the user.")
{#SGR-addUserQuery_S_O_O__ul_znd_wlp_53c}

Always 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.

You 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://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US).
{#SGR-addUserQuery_S_O_O__table_ix2_hvp_dt__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Table field name. |
| operator | Object | Query operator. The available values are dependent on the data type of the <var class="keyword varname">value</var> parameter. Numbers: * = * != * \> * \>= * \< * \<= {#SGR-addUserQuery_S_O_O__ul_qyb_rbt_3y} Strings (must be in upper case): * = * != * IN * NOT IN * STARTSWITH * ENDSWITH * CONTAINS * DOES NOT CONTAIN * INSTANCEOF {#SGR-addUserQuery_S_O_O__ul_egz_vbt_3y} Note: Use CONTAINS instead of the LIKE operator. Dynamic schema operators: * = * != * \< * \> * \<= * \>= * BETWEEN * CONTAINS * DOES_NOT_CONTAIN * ENDSWITH * GT_FIELD * GT_OR_EQUALS_FIELD * IN * ISEMPTY * ISNOTEMPTY * IS_NOT_NULL * IS_NULL * LIKE * LT_FIELD * LT_OR_EQUALS_FIELD * MATCHES * NOT_IN * NOT_LIKE * NOT_MATCHES * NSAMEAS * SAMEAS * STARTSWITH {#SGR-addUserQuery_S_O_O__ul_g5t_j32_cgc} |
| value | Object | Value on which to query (not case-sensitive). |
[Table 31. Parameters]

{#SGR-addUserQuery_S_O_O__table_ix2_hvp_dt} {#SGR-addUserQuery_S_O_O__table_gty_wtb_2r__entry__2}

| Type | Description |
|-|-|
| [GlideQueryCondition](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#c_GlideQueryConditionScopedAPI "The scoped GlideQueryCondition API provides additional AND or OR conditions that can be added to the current condition, allowing you to build complex queries.") | The query condition that was added to the GlideRecord. |
[Table 32. Returns]

{#SGR-addUserQuery_S_O_O__table_gty_wtb_2r}  
The following shows how to return only users named Fred that the current user has permission to see.

    var rec = new GlideRecord('sys_user');
    rec.addUserQuery("first_name", "=", "Fred");
    rec.query();

    while (rec.next()) {
      gs.info('Active user ' + rec.getValue('last_name'));
    }

Output:

    Active user Luddy
    Active user Kunde

## Scoped GlideRecord - canCreate() {#ariaid-title18}

Determines if the Access Control Rules, which include the user's roles, permit
inserting new records in this table.
{#r_ScopedGlideRecordCanCreate__table_vy2_535_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 33. Parameters]

{#r_ScopedGlideRecordCanCreate__table_vy2_535_jq} {#r_ScopedGlideRecordCanCreate__table_g2l_vtb_2r__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the user's roles permit creating of records in this table. Valid values: * true: Creating permitted * false: Creating is not permitted {#r_ScopedGlideRecordCanCreate__ul_vtm_pf2_t3b} |
[Table 34. Returns]

{#r_ScopedGlideRecordCanCreate__table_g2l_vtb_2r}  
This code example writes whether the current user can create records in the Incident table
in the system log.

    var now_GR = new GlideRecord('incident');
    gs.info(now_GR.canCreate());

## Scoped GlideRecord - canDelete() {#ariaid-title19}

Determines if the Access Control Rules, which include the user's roles, permit deleting
records in this table.
{#r_ScopedGlideRecordCanDelete__table_vy2_535_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 35. Parameters]

{#r_ScopedGlideRecordCanDelete__table_vy2_535_jq} {#r_ScopedGlideRecordCanDelete__table_pdw_ftb_2r__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the user's roles permit deleting of records in this table. Valid values: * true: Deleting permitted * false: Deleting is not permitted {#r_ScopedGlideRecordCanDelete__ul_vtm_pf2_t3b} |
[Table 36. Returns]

{#r_ScopedGlideRecordCanDelete__table_pdw_ftb_2r}  
This code example writes whether the current user can delete records in the Incident table
in the system log.

    var att = new GlideRecord('sys_attachment');
    gs.info(att.canDelete());

## Scoped GlideRecord - canRead() {#ariaid-title20}

Determines 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.
{#r_ScopedGlideRecordCanRead__table_vy2_5335_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 37. Parameters]

{#r_ScopedGlideRecordCanRead__table_vy2_5335_jq} {#r_ScopedGlideRecordCanRead__table_zmp_ttb_2r__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the user's roles permit reading of records in this table. Valid values: * true: Reading permitted * false: Reading is not permitted {#r_ScopedGlideRecordCanRead__ul_vtm_pf2_t3b} |
[Table 38. Returns]

{#r_ScopedGlideRecordCanRead__table_zmp_ttb_2r}  
This code example writes whether the current user can read records in the Incident table in
the system log.

    var now_GR = new GlideRecord('incident');
    gs.info(now_GR.canRead());

## Scoped GlideRecord - canWrite() {#ariaid-title21}

Determines if the Access Control Rules, which include the user's roles, permit editing
records in this table.
{#r_ScopedGlideRecordCanWrite__table_vxy2_535_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 39. Parameters]

{#r_ScopedGlideRecordCanWrite__table_vxy2_535_jq} {#r_ScopedGlideRecordCanWrite__table_sq3_ttb_2r__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the user's roles permit writing of records in this table. Valid values: * true: Writing permitted * false: Writing is not permitted |
[Table 40. Returns]

{#r_ScopedGlideRecordCanWrite__table_sq3_ttb_2r}  
This code example writes whether the current user can write records in the Incident table
in the system log.

    var now_GR = new GlideRecord('incident');
    gs.info(now_GR.canWrite());

## Scoped GlideRecord - chooseWindow(Number firstRow, Number lastRow, Boolean forceCount) {#ariaid-title22}

Sets a range of rows to be returned by subsequent queries.

Using setLimit() with chooseWindow()
:   The setLimit() method implicitly calls the chooseWindow() method and might cause unexpected results when used with chooseWindow() in a query.  
    * If the chooseWindow() method is called first, its record window is overwritten by the setLimit() method.  
      Using the following lines in a query returns 100 records starting at row 1:

          grIncident.chooseWindow(20,30);
          grIncident.setLimit(100);

    * If the setLimit() method is called first, the window set by chooseWindow() is used and the limit is overwritten.  
      Using the following lines in a query returns 10 records starting at row 21:

          grIncident.setLimit(5);
          grIncident.chooseWindow(20,30);

      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().
See also:

* [query()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordQuery_Object_Object "Runs a query against the table based on the filters specified in the query methods such as addQuery() and addEncodedQuery().")
* [setLimit()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordSetLimit_Number "Sets the limit for number of records are fetched by the GlideRecord query.")
* [setNoCount()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-setNoCount "Stops a GlideRecord query from running a COUNT(*) query.")
{#r_ScopedGlideRecordChooseWindow_Number_Number_Boolean__ul_zjw_cvd_xgc}
{#r_ScopedGlideRecordChooseWindow_Number_Number_Boolean__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| firstRow | Number | Zero-based index of the starting row for the range, inclusive. (A value of 0 returns the first row.) |
| lastRow | Number | Zero-based index of the ending row for the range, exclusive. For example, if firstRow = 1 and lastRow = 5, four records are returned (2-5). |
| forceCount | Boolean | Optional. 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: * true: Row count always occurs. * false: Row count occurs if implemented in normal execution of method. {#r_ScopedGlideRecordChooseWindow_Number_Number_Boolean__ul_fgp_42j_gqb} Default: false |
[Table 41. Parameters]

{#r_ScopedGlideRecordChooseWindow_Number_Number_Boolean__table_vy2_525_jq} {#r_ScopedGlideRecordChooseWindow_Number_Number_Boolean__table_rhg_rtb_2r__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 42. Returns]

{#r_ScopedGlideRecordChooseWindow_Number_Number_Boolean__table_rhg_rtb_2r}  
This example shows how to return records 3 and 4 from the Incident \[incident\] table.

    var now_GR = new GlideRecord('incident');
    now_GR.orderBy('number');
    now_GR.chooseWindow(2, 4);
    now_GR.query();
    while (now_GR.next()) {
      gs.info(now_GR.getValue('number') + ' is within window');
    }

Output:

    *** Script: INC0000003 is within window
    *** Script: INC0000004 is within window

## Scoped GlideRecord - deleteMultiple() {#ariaid-title23}

Deletes all records that satisfy the query.
This method does not delete attachments.

Do 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().

The 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://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US).
{#r_ScopedGlideRecordDeleteMultiple__table_vy2_51_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 43. Parameters]

{#r_ScopedGlideRecordDeleteMultiple__table_vy2_51_jq} {#r_ScopedGlideRecordDeleteMultiple__table_fpr_qtb_2r__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 44. Returns]

{#r_ScopedGlideRecordDeleteMultiple__table_fpr_qtb_2r}  
This example shows how to delete all inactive records from the Incident table.

    var now_GR = new GlideRecord('incident');
    now_GR.addQuery('active','false');
    now_GR.query();
    now_GR.deleteMultiple();

## Scoped GlideRecord - deleteRecord() {#ariaid-title24}

Deletes the current record.
{#r_ScopedGlideRecordDeleteRecord__table_vxy2_535_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 45. Parameters]

{#r_ScopedGlideRecordDeleteRecord__table_vxy2_535_jq} {#r_ScopedGlideRecordDeleteRecord__table_rrm_4tb_2r__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the record was successfully deleted. Valid values: * true: Record was deleted. * false: No record was found to delete. {#r_ScopedGlideRecordDeleteRecord__ul_hkn_5bj_s3b} |
[Table 46. Returns]

{#r_ScopedGlideRecordDeleteRecord__table_rrm_4tb_2r}  
This example shows how to delete a specified record from the Incident table.

    var now_GR = new GlideRecord('incident');
    //to delete one record
    if (now_GR.get('99ebb4156fa831005be8883e6b3ee4b9'))
        now_GR.deleteRecord();

This 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.

    var grTicket = new GlideRecord('incident');
    grTicket.initialize();
    grTicket.short_description = 'Example ticket';
    grTicket.work_notes = 'An update about the ticket';
    var ins_sys_id = grTicket.insert(); // Insert the record
    grTicket.get(ins_sys_id); // Reload the inserted record
    gs.info(grTicket.deleteRecord()); // Delete the record

Output:

    true

## Scoped GlideRecord - disableSysIdInOptimization() {#ariaid-title25}

Disables 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)`.
This 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).

If 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.
{#SGR-disableSysIdInOptimization__table_ilp_2cg_zcc__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 47. Parameters]

{#SGR-disableSysIdInOptimization__table_ilp_2cg_zcc} {#SGR-disableSysIdInOptimization__table_jlp_2cg_zcc__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 48. Returns]

{#SGR-disableSysIdInOptimization__table_jlp_2cg_zcc}  
The 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.

    var listOf200SysIds = [ ... ]; // 200 comma separated sys_ids
    var grIncident = new GlideRecord('incident');
    grIncident.addQuery('sys_id', 'IN', listOf200SysIds);
    grIncident.disableSysIdInOptimization(); // Rowcount could be incorrect without this method call
    grIncident.query();
    if (grIncident.next())
        gs.info("Rowcount: " + grIncident.getRowCount());

Output:

    Rowcount: 200

## Scoped GlideRecord - get(Object name, Object value) {#ariaid-title26}

Returns the specified record in the current GlideRecord object.
This 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.
{#r_ScopedGlideRecordGet_Object_Object__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| 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. |
| 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. |
[Table 49. Parameters]

{#r_ScopedGlideRecordGet_Object_Object__table_vy2_525_jq} {#r_ScopedGlideRecordGet_Object_Object__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Boolean | Indicates whether the requested record was located: * true: record was found * false: record was not found {#r_ScopedGlideRecordGet_Object_Object__ul_ngs_clw_qfb} |
[Table 50. Returns]

{#r_ScopedGlideRecordGet_Object_Object__table_qpt_3f5_jq}  
This example shows how to obtain an incident record by passing in the sys_id.

    var grIncident = new GlideRecord('incident');
    var returnValue = grIncident.get('99ebb4156fa831005be8883e6b3ee4b9');
    gs.info(returnValue); // logs true or false
    gs.info(grIncident.short_description); // logs Incident Short description

This 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.

    var grIncident = new GlideRecord('incident');
    var returnValue = grIncident.get('caller_id.name','Sylivia Wayland');
    gs.info(returnValue); // logs true or false
    gs.info(grIncident.getValue('number')); // logs Incident Number

## Scoped GlideRecord - getAttribute(String fieldName) {#ariaid-title27}

Returns the dictionary attributes for the specified field.
{#SGR-getAttribute_S__table_xqs_wfq_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| fieldName | String | Field name for which to return the dictionary attributes |
[Table 51. Parameters]

{#SGR-getAttribute_S__table_xqs_wfq_fz} {#SGR-getAttribute_S__table_yqs_wfq_fz__entry__2}

| Type | Description |
|-|-|
| String | Dictionary attributes |
[Table 52. Returns]

{#SGR-getAttribute_S__table_yqs_wfq_fz}  

    doit();
    function doit() {
      var now_GR = new GlideRecord('sys_user');
      now_GR.query("user_name","admin");
      if (now_GR.next()) {
        gs.info("we got one");
        gs.info(now_GR.location.getAttribute("tree_picker"));
      }
    }

## Scoped GlideRecord - getClassDisplayValue() {#ariaid-title28}

Returns the current table's label.
{#SGR-getClassDisplayValue__table_ltd_ydr_dt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 53. Parameters]

{#SGR-getClassDisplayValue__table_ltd_ydr_dt} {#SGR-getClassDisplayValue__table_mtd_ydr_dt__entry__2}

| Type | Description |
|-|-|
| String | Label that identifies the table. |
[Table 54. Returns]

{#SGR-getClassDisplayValue__table_mtd_ydr_dt}  
This example prints the label of the passed in table.

    // Display the incident table label
    var now_GR = new GlideRecord("incident");
    var value = now_GR.getClassDisplayValue();
    gs.info("The table label is " + value + ".");

Output:

    The table label is Incident.

## Scoped GlideRecord - getDisplayValue() {#ariaid-title29}

Retrieves the display value for the current record.
Display values are manipulated based on the actual value in the database and user or system
settings and preferences.  
The display value that is returned is dependent on the field type.

* Choice fields: The database value may be a number, but the display value will be more descriptive.
* Date fields: The database value is in UTC format, while the display value is based on the user's time zone.
* Encrypted text: The database value is encrypted, while the displayed value is unencrypted based on the user's encryption context.
* Reference fields: The database value is sys_id, but the display value is a display field of the referenced record.
{#r_ScopedGlideRecordGetDisplayValue__ul_ok1_cbv_hsb}
{#r_ScopedGlideRecordGetDisplayValue__table_dgk_dtb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 55. Parameters]

{#r_ScopedGlideRecordGetDisplayValue__table_dgk_dtb_2r} {#r_ScopedGlideRecordGetDisplayValue__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Display value for the current record. |
[Table 56. Returns]

{#r_ScopedGlideRecordGetDisplayValue__table_qpt_3f5_jq}  
This example writes the display value of a specified incident record into the log.

    var now_GR = new GlideRecord('incident');
    now_GR.get('sys_id','<sys_id>');
    gs.info(now_GR.getDisplayValue());

Output:

    INC0000050

## Scoped GlideRecord - getED() {#ariaid-title30}

Returns the element's descriptor.
{#SGR-getED__table_xvc_xjq_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 57. Parameters]

{#SGR-getED__table_xvc_xjq_fz} {#SGR-getED__table_qpq_p2r_dt__entry__2}

| Type | Description |
|-|-|
| GlideElementDescriptor | The element's descriptor. |
[Table 58. Returns]

{#SGR-getED__table_qpq_p2r_dt}  
This example shows how to retrieve the name field for an incident GlideRecord.

    var grInc = new GlideRecord('incident');
    grInc.get('sys_id','ef43c6d40a0a0b5700c77f9bf387afe3');

    var field = grInc.getElement('priority');
    var ed = field.getED();

    var isEdge = ed.getLabel();
    gs.info("Label is - " + isEdge);

Output:

    Label is - Priority

## Scoped GlideRecord - getElement(String fieldName) {#ariaid-title31}

Retrieves the GlideElement object for the specified field.
The 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`.

In 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.

Instead of retrieving the entire object, you can
use one of the following methods to copy the field values:  
* [getValue()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordGetValue_String "Retrieves the string value of an underlying element in a field.")
* [getDisplayValue()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordGetDisplayValue "Retrieves the display value for the current record.")
{#r_ScopedGlideRecordGetElement_String__ul_lgx_d2d_zpb}  
If 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:

    var mgr = current.caller_id.manager.toString();

See also:

* [GlideElement -- toString()](https://www.servicenow.com/docs/n4FSgCkxOii7rIaF5cOhDg#r_ScopedGlideElementToString "Converts the value of a GlideRecord field to a string.")
* [getElements()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-getElements "Returns an array of GlideElement objects. Each object describes a field in the current GlideRecord.")
{#r_ScopedGlideRecordGetElement_String__ul_mmb_3h3_npb}
{#r_ScopedGlideRecordGetElement_String__id_xzl_rpn_mpb__entry__3}

| Name | Type | Description |
|-|-|-|
| fieldName | String | Column name for which to return the GlideElement object. |
[Table 59. Parameters]

{#r_ScopedGlideRecordGetElement_String__id_xzl_rpn_mpb} {#r_ScopedGlideRecordGetElement_String__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| GlideElement | The GlideElement for the specified column of the current record. Each object describes a field in the current GlideRecord. |
[Table 60. Returns]

{#r_ScopedGlideRecordGetElement_String__table_qpt_3f5_jq}  
The following example shows how to add a new incident record with details in the
Short Description field.

    var elementName = 'short_description'; 
    var now_GR = new GlideRecord('incident'); 
    now_GR.newRecord(); 
    now_GR.setValue(elementName, "My DB is not working");
    now_GR.insert();
     
    var sdesc = now_GR.getElement('short_description');
    gs.info(sdesc.getValue());

Output:

    My DB is not working

## Scoped GlideRecord - getElements() {#ariaid-title32}

Returns an array of GlideElement objects. Each object describes a field in the current
GlideRecord.
If 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:

    var mgr = current.caller_id.manager.toString();

See also:

* [GlideElement -- toString()](https://www.servicenow.com/docs/n4FSgCkxOii7rIaF5cOhDg#r_ScopedGlideElementToString "Converts the value of a GlideRecord field to a string.")
* [getElement()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordGetElement_String "Retrieves the GlideElement object for the specified field.")
{#SGR-getElements__ul_mmb_3h3_npb}
{#SGR-getElements__table_qcv_tfp_pnb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 61. Parameters]

{#SGR-getElements__table_qcv_tfp_pnb} {#SGR-getElements__table_rcv_tfp_pnb__entry__2}

| Type | Description |
|-|-|
| Array | Array of [GlideElement](https://www.servicenow.com/docs/n4FSgCkxOii7rIaF5cOhDg#c_GlideElementScopedAPI "The scoped GlideElement API provides a number of convenient script methods for dealing with fields and their values. Scoped GlideElement methods are available for the fields of the current glide record.") objects. Each object describes a field in the current GlideRecord. |
[Table 62. Returns]

{#SGR-getElements__table_rcv_tfp_pnb}  
The following example displays the value of the name field for the five most recent records
created in the Question \[question\] table.

    var now_GR = new GlideRecord('question');
    var elementArr = now_GR.getElements();
    now_GR.orderByDesc('sys_created_on');
    now_GR.setLimit(5);
    now_GR.query();

    while (now_GR.next()){
      var qNames = now_GR.name.toString();
      elementArr.push(qNames);
      gs.info(qNames);
    }

Output:

    delivery_time_var
    delivery_time
    sequence
    priority
    assigned_group

## Scoped GlideRecord - getEncodedQuery() {#ariaid-title33}

Retrieves the query condition of the current result set as an encoded query string.
{#r_ScopedGlideRecordGetEncodedQuery__table_pyd_dtb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 63. Parameters]

{#r_ScopedGlideRecordGetEncodedQuery__table_pyd_dtb_2r} {#r_ScopedGlideRecordGetEncodedQuery__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | An [encoded query string](https://www.servicenow.com/docs/access?context=c_EncodedQueryStrings&version=zurich&pubname=zurich-platform-user-interface&ft:locale=en-US). |
[Table 64. Returns]

{#r_ScopedGlideRecordGetEncodedQuery__table_qpt_3f5_jq}  

    var now_GR = new GlideRecord('incident'); 
    now_GR.addQuery('active', true);
    now_GR.addQuery('priority', 1); 
    now_GR.query(); 
    var encodedQuery = now_GR.getEncodedQuery(); 
    gs.info(encodedQuery);

Output:

    active=true^priority=1

## Scoped GlideRecord - getLabel() {#ariaid-title34}

Returns the field's label.
{#SGR-getLabel__table_edc_vkq_fz__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 65. Parameters]

{#SGR-getLabel__table_edc_vkq_fz} {#SGR-getLabel__table_fdc_vkq_fz__entry__2}

| Type | Description |
|-|-|
| String | Field's label |
[Table 66. Returns]

{#SGR-getLabel__table_fdc_vkq_fz}  

    template.print("Summary of Requested items:\n");  
    var now_GR = new GlideRecord("sc_req_item");
    now_GR.addQuery("request", current.sysapproval);
    now_GR.query();
    while(now_GR.next()) {
    var nicePrice = now_GR.price.toString();
      if (nicePrice != '') {
        nicePrice = parseFloat(nicePrice);
        nicePrice = nicePrice.toFixed(2);
      }
      template.print(now_GR.number + ":  " + now_GR.quantity + " X " + now_GR.cat_item.getDisplayValue() 
        + " at $" + nicePrice + " each \n");
      template.print("    Options:\n");
      for (key in now_GR.variables) {
      var now_V = now_GR.variables[key];
        if(now_V.getGlideObject().getQuestion().getLabel() != '') {
          template.space(4);
          template.print('     ' +  now_V.getGlideObject().getQuestion().getLabel() + " = " 
            + now_V.getDisplayValue() + "\n");  
        }
      }
    }

## Scoped GlideRecord - getLastErrorMessage() {#ariaid-title35}

Retrieves the last error message. If there is no last error message, null is returned.
{#r_ScopedGlideRecordGetLastErrorMessage__table_cfw_ctb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 67. Parameters]

{#r_ScopedGlideRecordGetLastErrorMessage__table_cfw_ctb_2r} {#r_ScopedGlideRecordGetLastErrorMessage__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | The last error message as a string. |
[Table 68. Returns]

{#r_ScopedGlideRecordGetLastErrorMessage__table_qpt_3f5_jq}  

    // Setup a data policy where short_description field in incident is mandatory
    var now_GR = new GlideRecord('incident');
    now_GR.insert(); // insert without data in mandatory field
    var errormessage = now_GR.getLastErrorMessage(); 
    gs.info(errormessage);

Output:

    Data Policy Exception: Short description is mandatory

## Scoped GlideRecord - getLink(Boolean noStack) {#ariaid-title36}

Retrieves the link to the current record.
{#r_ScopedGlideRecordGetLink_Boolean__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| noStack | Boolean | Flag 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: * true: Do not attach the sysparm_stack parameter. * false: Attach the sysparm_stack parameter. {#r_ScopedGlideRecordGetLink_Boolean__ul_fsf_wpz_1nb}If true, the sysparm_stack parameter is not appended to the link. |
[Table 69. Parameters]

{#r_ScopedGlideRecordGetLink_Boolean__table_vy2_525_jq} {#r_ScopedGlideRecordGetLink_Boolean__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Link to the current record. |
[Table 70. Returns]

{#r_ScopedGlideRecordGetLink_Boolean__table_qpt_3f5_jq}  
This 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.

    var now_GR = new GlideRecord('incident');
    now_GR.addActiveQuery();
    now_GR.addQuery("priority", 1);
    now_GR.query();
    now_GR.next();
    gs.info(gs.getProperty('glide.servlet.uri') + now_GR.getLink(false));

Output:

    https://instance.service-now.com/incident.do?sys_id=46e2fee9a9fe19810049b49dee0daf58&sysparm_stack=incident_list.do?sysparm_query=active=true

## Scoped GlideRecord - getRecordClassName() {#ariaid-title37}

Retrieves the class name for the current record.
{#r_ScopedGlideRecordGetRecordClassName__table_srq_ctb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 71. Parameters]

{#r_ScopedGlideRecordGetRecordClassName__table_srq_ctb_2r} {#r_ScopedGlideRecordGetRecordClassName__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | The class name. |
[Table 72. Returns]

{#r_ScopedGlideRecordGetRecordClassName__table_qpt_3f5_jq}  

    var now_GR = new GlideRecord('incident'); 
    var recordClassName = now_GR.getRecordClassName(); 
    gs.info(recordClassName);

Output:

    incident

## Scoped GlideRecord - getRowCount() {#ariaid-title38}

Retrieves the number of rows (records) in the current GlideRecord object.
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.  

Retrieving the number of records in GlideRecord or GlideAggregate
:   The GlideRecord getRowCount() and [GlideAggregate getAggregate()](https://www.servicenow.com/docs/QWkkDv0bsvqUeYStHWuhbg#c_GlideAggregateScopedAPI "The GlideAggregate API enables creating database aggregation queries.") APIs offer similar information. Use the following criteria to determine which option is best for you.

    * 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.
    * 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.
    {#r_ScopedGlideRecordGetRowCount__ul_wdq_fmn_nyb}
:   Retrieving the records and count with GlideRecord getRowCount()  
    The following example shows how to get the total number of active incidents with GlideRecord getRowCount():

        var incident = new GlideRecord("incident");
        incident.addQuery("active", true);
        incident.query();
         
        gs.info("*** Total number of active incidents: {0}", incident.getRowCount());

:   Retrieving only the number of records with GlideAggregate getAggregate()  
    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.

        var incident = new GlideAggregate("incident");
        incident.addQuery("active", true);
        incident.addAggregate("COUNT");
        incident.query();
         
        if (incident.next())
            gs.info("*** Total number of active incidents: {0}", incident.getAggregate("COUNT"));

:   Deciding which option is best for your solution

    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.  
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:

* Call the disableSysIdInOptimization() method on the GlideRecord.
* 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.

{#r_ScopedGlideRecordGetRowCount__ul_j1v_ztm_zcc} In addition, ensure that you call the .next() method before calling the getRowCount() method.
{#r_ScopedGlideRecordGetRowCount__table_dxv_hkr_dt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 73. Parameters]

{#r_ScopedGlideRecordGetRowCount__table_dxv_hkr_dt} {#r_ScopedGlideRecordGetRowCount__table_exv_hkr_dt__entry__2}

| Type | Description |
|-|-|
| Number | Number of rows in the current GlideRecord. |
[Table 74. Returns]

{#r_ScopedGlideRecordGetRowCount__table_exv_hkr_dt}  
The following example shows how to get the number of incidents from the Incident \[incident\] table.

    var numberOfIncidents = new GlideRecord('incident');
    numberOfIncidents.query();
    gs.info("Records in incident table: " + numberOfIncidents.getRowCount());

Output:

    Records in incident table: 6920

The 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.

    var listOf200SysIds = [ ... ]; // 200 comma separated sys_ids
    var grIncident = new GlideRecord('incident');
    grIncident.addQuery('sys_id', 'IN', listOf200SysIds);
    grIncident.disableSysIdInOptimization(); // Rowcount could be incorrect without this method call
    grIncident.query();
    if (grIncident.next())
        gs.info("Rowcount: " + grIncident.getRowCount());

Output:

    Rowcount: 200

## Scoped GlideRecord - getTableName() {#ariaid-title39}

Retrieves the name of the table associated with the GlideRecord.
{#r_ScopedGlideRecordGetTableName__table_z5p_btb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 75. Parameters]

{#r_ScopedGlideRecordGetTableName__table_z5p_btb_2r} {#r_ScopedGlideRecordGetTableName__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | The table name |
[Table 76. Returns]

{#r_ScopedGlideRecordGetTableName__table_qpt_3f5_jq}  

    var now_GR = new GlideRecord('incident');
    gs.info(now_GR.getTableName());

## Scoped GlideRecord - getUniqueValue() {#ariaid-title40}

Gets the primary key of the record, which is usually the sys_id unless otherwise
specified.
{#r_ScopedGlideRecordGetUniqueValue__table_t5k_btb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 77. Parameters]

{#r_ScopedGlideRecordGetUniqueValue__table_t5k_btb_2r} {#r_ScopedGlideRecordGetUniqueValue__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | The unique primary key as a String, or null if the key is null. |
[Table 78. Returns]

{#r_ScopedGlideRecordGetUniqueValue__table_qpt_3f5_jq}  

    var now_GR = new GlideRecord('kb_knowledge');
    now_GR.query();
    now_GR.next();
    var uniqueid = now_GR.getUniqueValue();
    gs.info(uniqueid);

## Scoped GlideRecord - getValue(String name) {#ariaid-title41}

Retrieves the string value of an underlying element in a field.
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://www.servicenow.com/docs/access?context=encryption-landing&version=zurich&pubname=zurich-platform-security&ft:locale=en-US).
{#r_ScopedGlideRecordGetValue_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | The name of the field to get the value from. |
[Table 79. Parameters]

{#r_ScopedGlideRecordGetValue_String__table_vy2_525_jq} {#r_ScopedGlideRecordGetValue_String__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| 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 <kbd class="ph userinput">"0"</kbd> and <kbd class="ph userinput">"1"</kbd> string values instead of false and true. |
[Table 80. Returns]

{#r_ScopedGlideRecordGetValue_String__table_qpt_3f5_jq}  

    var now_GR = new GlideRecord('incident'); 
    now_GR.orderBy('number');
    now_GR.query('active','true'); 
    now_GR.next(); 
    gs.info(now_GR.getValue('number'));

Output:

    INC0000002

## Scoped GlideRecord - GlideRecord(String tableName) {#ariaid-title42}

Creates an instance of the GlideRecord class for the specified table.
{#r_ScopedGlideRecordGlideRecord_S__table_hlc_w5j_3v__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | The table to be used. |
[Table 81. Parameters]

{#r_ScopedGlideRecordGlideRecord_S__table_hlc_w5j_3v}  

    var now_GR = new GlideRecord('incident');

## Scoped GlideRecord - hasNext() {#ariaid-title43}

Determines if there are any more records in the GlideRecord object.
{#r_ScopedGlideRecordHasNext__table_nmb_btb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 82. Parameters]

{#r_ScopedGlideRecordHasNext__table_nmb_btb_2r} {#r_ScopedGlideRecordHasNext__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Boolean | True if there are more records in the query result set. |
[Table 83. Returns]

{#r_ScopedGlideRecordHasNext__table_qpt_3f5_jq}  

    var rec = new GlideRecord('incident'); 
    rec.query(); 
    if (rec.hasNext()) { 
      gs.info("Table is not empty"); 
    }

## Scoped GlideRecord - insert() {#ariaid-title44}

Inserts a new record using the field values that have been set for the current record.
{#r_ScopedGlideRecordInsert__table_sks_1tb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 84. Parameters]

{#r_ScopedGlideRecordInsert__table_sks_1tb_2r} {#r_ScopedGlideRecordInsert__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Sys_id of the inserted record, or null if the record is not inserted. |
[Table 85. Returns]

{#r_ScopedGlideRecordInsert__table_qpt_3f5_jq}  

    var now_GR = new GlideRecord('incident');
    now_GR.initialize();
    now_GR.setValue('name', 'New Incident');
    now_GR.setValue('description', 'Incident description');
    now_GR.insert();

Output:

    138fb4111b4d4d907cf30d03cd4bcb57

## Scoped GlideRecord - initialize() {#ariaid-title45}

Creates an empty record suitable for population before an insert.
{#r_ScopedGlideRecordInitialize__table_onw_1tb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 86. Parameters]

{#r_ScopedGlideRecordInitialize__table_onw_1tb_2r} {#r_ScopedGlideRecordInitialize__table_gnr_mtb_2r__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 87. Returns]

{#r_ScopedGlideRecordInitialize__table_gnr_mtb_2r}  

    var grIncident = new GlideRecord('incident');
    grIncident.initialize();
    grIncident.setValue('short_description', 'New Incident');
    grIncident.setValue('description', 'Incident description');
    grIncident.insert();

## Scoped GlideRecord - isActionAborted() {#ariaid-title46}

Checks to see if the current database action is to be aborted.
isActionAborted() is initialized (set to false) for new threads and by
the next() method.
{#r_ScopedGlideRecordIsActionAborted__table_gqg_mvt_vr__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 88. Parameters]

{#r_ScopedGlideRecordIsActionAborted__table_gqg_mvt_vr} {#r_ScopedGlideRecordIsActionAborted__table_hqg_mvt_vr__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates if the current database action is to be aborted. Valid values: * true: The current database action is to be aborted. * false: The current database action is not to be aborted. {#r_ScopedGlideRecordIsActionAborted__ul_l5r_kjq_kpb} |
[Table 89. Returns]

{#r_ScopedGlideRecordIsActionAborted__table_hqg_mvt_vr}  

    var now_GR = new GlideRecord('incident');
     
    gs.info(now_GR.isActionAborted());

Output:

    false

## Scoped GlideRecord - isEncodedQueryValid(String query) {#ariaid-title47}

Verifies whether the specified encoded query is valid.
If the specified encoded query is valid, then the query is applied, just as if you had
called [addEncodedQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordAddEncodedQuery_String "Adds an encoded query to other queries that may have been set.").
If the specified encoded query is invalid, then `sys_idNotValidnull` is added
as the encoded query.  
Note:  
This method has been deprecated and replaced with the [isValidEncodedQuery()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-isValidEncodedQuery_S "Verifies whether the syntax of the encoded query is correct.") method which does not execute the query.
{#SGR-isEncodedQueryValid_S__table_nbb_bv4_2gb__entry__3}

| Name | Type | Description |
|-|-|-|
| query | String | Encoded query to validate. See [Encoded query strings](https://www.servicenow.com/docs/access?context=c_EncodedQueryStrings&version=zurich&pubname=zurich-platform-user-interface&ft:locale=en-US). |
[Table 90. Parameters]

{#SGR-isEncodedQueryValid_S__table_nbb_bv4_2gb} {#SGR-isEncodedQueryValid_S__table_obb_bv4_2gb__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the specified encoded query is valid. * true: Passed-in encoded query is valid. * false: Passed-in encoded query is not valid. |
[Table 91. Returns]

{#SGR-isEncodedQueryValid_S__table_obb_bv4_2gb}  
This code example shows how to validate an encoded query and then execute logic if the
query is valid.

    var now_GR = new GlideRecord('incident_sla');
    var isValidQuery = now_GR.isEncodedQueryValid('inc_impact=1^taskslatable_active=true');
    if (isValidQuery) {
      now_GR.query();
      .
      .
      .
    }

## Scoped GlideRecord - isNewRecord() {#ariaid-title48}

Checks if the current record is a new record that has not yet been inserted into the
database.
{#r_ScopedGlideRecordIsNewRecord__table_lhn_1tb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 92. Parameters]

{#r_ScopedGlideRecordIsNewRecord__table_lhn_1tb_2r} {#r_ScopedGlideRecordIsNewRecord__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the record is new and has not been inserted into the database. |
[Table 93. Returns]

{#r_ScopedGlideRecordIsNewRecord__table_qpt_3f5_jq}  

    var now_GR = new GlideRecord("x_app_table"); 
    now_GR.newRecord(); // create a new record and populate it with default values
    gs.info(now_GR.isNewRecord());

## Scoped GlideRecord - isValid() {#ariaid-title49}

Determines if the current table is valid or if the record was successfully
retrieved.
{#r_ScopedGlideRecordIsValid__table_ub3_1tb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 94. Parameters]

{#r_ScopedGlideRecordIsValid__table_ub3_1tb_2r} {#r_ScopedGlideRecordIsValid__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates if the table is valid or if the record was successfully retrieved. Possible values: * true: Table is valid or the record was successfully retrieved. * false: Table is invalid or the record was not successfully retrieved. {#r_ScopedGlideRecordIsValid__ul_rr1_3m4_pnb} |
[Table 95. Returns]

{#r_ScopedGlideRecordIsValid__table_qpt_3f5_jq}  

    var comment_GR = new GlideRecord('cf_comment');
    var commentId = '99ebb4156fa831005be8883e6b3ee4b9';
    comment_GR.get(commentId);
    gs.info(comment_GR.isValid());

## Scoped GlideRecord - isValidEncodedQuery(String query) {#ariaid-title50}

Verifies whether the syntax of the encoded query is correct.
When passing an empty string (`""`) as the provide query:

* The empty string (`""`) represents the absence of a query and returns false.
* 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).
{#SGR-isValidEncodedQuery_S__ul_trc_ldy_hcc}
{#SGR-isValidEncodedQuery_S__table_urg_zqs_j5b__entry__3}

| Name | Type | Description |
|-|-|-|
| query | String | Encoded query to validate. See [Encoded query strings](https://www.servicenow.com/docs/access?context=c_EncodedQueryStrings&version=zurich&pubname=zurich-platform-user-interface&ft:locale=en-US). |
[Table 96. Parameters]

{#SGR-isValidEncodedQuery_S__table_urg_zqs_j5b} {#SGR-isValidEncodedQuery_S__table_vrg_zqs_j5b__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the specified encoded query is valid. * true: Passed-in encoded query is valid. * false: Passed-in encoded query is not valid. {#SGR-isValidEncodedQuery_S__ul_xcw_xcy_hcc} |
[Table 97. Returns]

{#SGR-isValidEncodedQuery_S__table_vrg_zqs_j5b}  
This code example shows how to check if the encoded query is valid.

    var queryString = "priority=1^ORpriority=2";
    var now_GR = new GlideRecord('incident');
    var isValidQuery = now_GR.isValidEncodedQuery(queryString);
    if (isValidQuery) {
      now_GR.addEncodedQuery(queryString);
      now_GR.query();
      .
      .
      .
    }

## Scoped GlideRecord - isValidField(String columnName) {#ariaid-title51}

Determines if the specified field is defined in the current table.
{#r_ScopedGlideRecordIsValidField__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| columnName | String | The name of the field. |
[Table 98. Parameters]

{#r_ScopedGlideRecordIsValidField__table_vy2_525_jq} {#r_ScopedGlideRecordIsValidField__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the field is defined for the current table. |
[Table 99. Returns]

{#r_ScopedGlideRecordIsValidField__table_qpt_3f5_jq}  

    var now_GR = new GlideRecord('incident'); 
    now_GR.initialize(); 
    gs.info(now_GR.isValidField("short_description"));

## Scoped GlideRecord - isValidRecord() {#ariaid-title52}

Determines if a record was actually returned by the query/get record
operation.
{#r_ScopedGlideRecordIsValidRecord__table_o1w_zsb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 100. Parameters]

{#r_ScopedGlideRecordIsValidRecord__table_o1w_zsb_2r} {#r_ScopedGlideRecordIsValidRecord__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether a record was actually returned by the query/get operation. Valid values: * true: Record returned by query/get operation. * false: End of record set, no record returned. {#r_ScopedGlideRecordIsValidRecord__ul_xzx_jnh_s3b} |
[Table 101. Returns]

{#r_ScopedGlideRecordIsValidRecord__table_qpt_3f5_jq}  

    var rec = new GlideRecord('incident');
    rec.query();
    while (rec.next()) { 
      gs.info(rec.number + ' exists');
    }
    gs.info(rec.isValidRecord());

## Scoped GlideRecord - isView() {#ariaid-title53}

Verifies whether the record was created in a view or a table.
{#SGR-isView__table_nbb_bv4_2gb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 102. Parameters]

{#SGR-isView__table_nbb_bv4_2gb} {#SGR-isView__table_obb_bv4_2gb__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the record was created in table that is a view. * true: The record was created in a view. * false: The record was created in a table. |
[Table 103. Returns]

{#SGR-isView__table_obb_bv4_2gb}  
This code example shows how to determine if a GlideRecord was created in a view or a
table.

    var mySLA = new GlideRecord('incident_sla');

    if (mySLA.isView() == true){
       gs.info('This record was created in a view.');
    } else {
       gs.info('This record was created in a table.');
    }

Output:

    This record was created in a view.

## Scoped GlideRecord - newRecord() {#ariaid-title54}

Creates a new GlideRecord record, sets the default values for the fields, and assigns a
unique ID to the record.
{#r_ScopedGlideRecordNewRecord__table_ls4_zsb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 104. Parameters]

{#r_ScopedGlideRecordNewRecord__table_ls4_zsb_2r} {#r_ScopedGlideRecordNewRecord__table_sgv_ktb_2r__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 105. Returns]

{#r_ScopedGlideRecordNewRecord__table_sgv_ktb_2r}  

    var now_GR = new GlideRecord("x_app_table"); 
    now_GR.newRecord(); 
    gs.info(now_GR.isNewRecord());

Output:

    true

## Scoped GlideRecord - next() {#ariaid-title55}

Moves to the next record in the GlideRecord object.
Note:  
This method fails if there is a field in the table called "next". If that is the case, use the method [_next()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-_next "Moves to the next record in the GlideRecord. Provides the same functionality as next(), use this method if the GlideRecord has a column named next.").
{#r_ScopedGlideRecordNext__table_nmg_zsb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 106. Parameters]

{#r_ScopedGlideRecordNext__table_nmg_zsb_2r} {#r_ScopedGlideRecordNext__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates if there is a "next" record in the GlideRecord. Valid values: * true: Move to the next record was successful. * false: No more records in the result set. {#r_ScopedGlideRecordNext__ul_anq_km4_s3b} |
[Table 107. Returns]

{#r_ScopedGlideRecordNext__table_qpt_3f5_jq}  

    var rec = new GlideRecord('incident');
    rec.query();
    while (rec.next()) {
     gs.info(rec.getValue('number') + ' exists');
    }

Output:

    INC0010112 exists
    INC0010114 exists
    INC0010119 exists
    INC0010127 exists

## Scoped GlideRecord - _next() {#ariaid-title56}

Moves to the next record in the GlideRecord. Provides the same functionality as
next(), use this method if the GlideRecord has a column named
next.
{#SGR-_next__table_e3x_4yj_my__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 108. Parameters]

{#SGR-_next__table_e3x_4yj_my} {#SGR-_next__table_f3x_4yj_my__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether there are more records in the query set. Possible values: * true: More records in the query set. * false: No more records in the query set. {#SGR-_next__ul_nzg_xkm_knb} |
[Table 109. Returns]

{#SGR-_next__table_f3x_4yj_my}  
The following example shows how to list each record in the Incidents \[incident\] table.

    var rec = new GlideRecord('incident');
    rec.query();
    while (rec._next()) {
      gs.info(rec.getValue('number') + ' exists');
    }

Output:

    INC0000060 exists
    INC0009002 exists
    INC0000009 exists
    INC0000010 exists
    INC0000011 exists
    INC0000012 exists
    ...

## Scoped GlideRecord - operation() {#ariaid-title57}

Determines if an operation is insert, update, or delete.
Knowing the operation enables using
current.operation() to make a generic business rule which can handle
each operation uniquely.

For information on using the global variable current, refer to [Global variables in business
rules](https://www.servicenow.com/docs/WlmNSCk28ZONmvETDNSgSg#c_UsingPredefinedGlobalVariables "Predefined global variables are available for use in business rules.").
{#r_ScopedGlideRecordOperation__table_tfc_zsb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 110. Parameters]

{#r_ScopedGlideRecordOperation__table_tfc_zsb_2r} {#r_ScopedGlideRecordOperation__gr-operation-returns__entry__2}

| Type | Description |
|-|-|
| String | The current operation. Possible values: * delete * insert * update {#r_ScopedGlideRecordOperation__ul_bnp_xs3_bpb} |
[Table 111. Returns]

{#r_ScopedGlideRecordOperation__gr-operation-returns}  
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.

    if(current.operation() == "update") {
      current.updates ++; } 
    if(current.operation() == "insert") {
      current.updates = 0; }

## Scoped GlideRecord - orderBy(String name) {#ariaid-title58}

Specifies an orderBy column.
Call 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://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordOrderByDesc_String "Specifies a descending orderBy column.").  
Note:  
To enforce query access based on the user, use [addUserOrderBy()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserOrderBy_S "Specifies an orderBy column. Use this method to enforce query access based on the user.").
{#r_ScopedGlideRecordOrderBy_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Column name to use to order the records in this GlideRecord object. |
[Table 112. Parameters]

{#r_ScopedGlideRecordOrderBy_String__table_vy2_525_jq} {#r_ScopedGlideRecordOrderBy_String__table_ts3_ktb_2r__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 113. Returns]

{#r_ScopedGlideRecordOrderBy_String__table_ts3_ktb_2r}  
The following example shows how to order incident records in ascending order by Short
Description.

    var queryString = "priority=2";
    var now_GR = new GlideRecord('incident');
    now_GR.orderBy('short_description'); // Ascending Order
    now_GR.addEncodedQuery(queryString);
    now_GR.query();
    while (now_GR.next()) {
      gs.info(now_GR.getValue('short_description'));
    }

Output:

    Can't launch 64-bit Windows 7 virtual machine
    Can't log into SAP from my laptop today
    Network storage unavailable
    Please remove the latest hotfix from my PC

## Scoped GlideRecord - orderByDesc(String name) {#ariaid-title59}

Specifies a descending orderBy column.
Call 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://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordOrderBy_String "Specifies an orderBy column.").  
Note:  
To enforce query access based on the user, use [addUserOrderByDesc()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-addUserOrderByDesc_S "Specifies a descending orderBy column. Use this method to enforce query access based on the user.").
{#r_ScopedGlideRecordOrderByDesc_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Column name to use to order the records in a GlideRecord object. |
[Table 114. Parameters]

{#r_ScopedGlideRecordOrderByDesc_String__table_vy2_525_jq} {#r_ScopedGlideRecordOrderByDesc_String__table_lpd_ktb_2r__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 115. Returns]

{#r_ScopedGlideRecordOrderByDesc_String__table_lpd_ktb_2r}  
The following example shows how to order incident records in descending order by Short
Description.

    var queryString = "priority=2";
    var now_GR = new GlideRecord('incident');
    now_GR.orderByDesc('short_description'); //Descending Order
    now_GR.addEncodedQuery(queryString);
    now_GR.query();
    while (now_GR.next()) {
      gs.info(now_GR.getValue('short_description'));
    }

Output:

    Please remove the latest hotfix from my PC
    Network storage unavailable
    Can't log into SAP from my laptop today
    Can't launch 64-bit Windows 7 virtual machine

## Scoped GlideRecord - query(String field, String value) {#ariaid-title60}

Runs a query against the table based on the filters specified in the query methods such as addQuery() and addEncodedQuery().
This method queries the GlideRecord table as well as any references of the table. For more information, see [Querying tables in script](https://www.servicenow.com/docs/Y~nD1FOgoLqUiVUAWKq6_w#c_UsingGlideRecordToQueryTables "Using methods in the GlideRecord API, you can return all records from a table, return records from a table that satisfy specific conditions, or return records that include a string from a single table or from multiple tables in a text index group.").  
Note:  
This method fails if there is a field in the table called "query". If that is the case, use the[_query()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-_query_O_O "Runs 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.") method instead.

See 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.  
See also:

* [GlideAggregate - Scoped](https://www.servicenow.com/docs/QWkkDv0bsvqUeYStHWuhbg#c_GlideAggregateScopedAPI "The GlideAggregate API enables creating database aggregation queries.")
* [GlideQuery - Scoped, Global](https://www.servicenow.com/docs/zTF54acHaiNEOuN28cn_9A#GlideQueryGlobalAPI "The GlideQuery script include is an alternative to the GlideRecord API for performing CRUD operations on record data from server-side scripts.")
* [GlideQueryCondition - Scoped](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#c_GlideQueryConditionScopedAPI "The scoped GlideQueryCondition API provides additional AND or OR conditions that can be added to the current condition, allowing you to build complex queries.")
{#r_ScopedGlideRecordQuery_Object_Object__ul_u5g_4gd_lpb}
{#r_ScopedGlideRecordQuery_Object_Object__id_nxt_s5d_lpb__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Optional - 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. |
| value | String | Optional - must also specify a field parameter. Value to search for in the specified field parameter. |
[Table 116. Parameters]

{#r_ScopedGlideRecordQuery_Object_Object__id_nxt_s5d_lpb} {#r_ScopedGlideRecordQuery_Object_Object__table_bkz_jtb_2r__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 117. Returns]

{#r_ScopedGlideRecordQuery_Object_Object__table_bkz_jtb_2r}  
The following example shows how to scan the System Dictionary \[sys_dictionary\] for tables
with a query field.

    var tableArr = [];

    var now_GR = new GlideRecord('sys_dictionary');
    now_GR.addQuery('element', 'query');
    now_GR.setLimit(6);

    now_GR.query();

    while(now_GR.next()){
       tableArr.push(now_GR.name.getValue());
    };

    gs.info('The following tables have a field column called "query":');

    for (i = 0; i < tableArr.length; i++) {
       gs.info(tableArr[i]);
    };

Output:

    The following tables have a field column called "query":
    cmdb_convert_bulk_services
    cmdb_multisource_query_status
    cmdb_qb_result_base
    cmdb_qb_table_mapping
    discovery_probes_cim_query
    kb_feedback

## Scoped GlideRecord - _query(String field, String value) {#ariaid-title61}

Runs 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.
This method queries the GlideRecord table as well as any references of the table. For more information, see [Querying tables in script](https://www.servicenow.com/docs/Y~nD1FOgoLqUiVUAWKq6_w#c_UsingGlideRecordToQueryTables "Using methods in the GlideRecord API, you can return all records from a table, return records from a table that satisfy specific conditions, or return records that include a string from a single table or from multiple tables in a text index group.").

See 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.  
See also:

* [GlideAggregate - Scoped](https://www.servicenow.com/docs/QWkkDv0bsvqUeYStHWuhbg#c_GlideAggregateScopedAPI "The GlideAggregate API enables creating database aggregation queries.")
* [GlideQuery - Scoped, Global](https://www.servicenow.com/docs/zTF54acHaiNEOuN28cn_9A#GlideQueryGlobalAPI "The GlideQuery script include is an alternative to the GlideRecord API for performing CRUD operations on record data from server-side scripts.")
* [GlideQueryCondition - Scoped](https://www.servicenow.com/docs/p8pf24IAVAq3SSy2Fpgcvw#c_GlideQueryConditionScopedAPI "The scoped GlideQueryCondition API provides additional AND or OR conditions that can be added to the current condition, allowing you to build complex queries.")
{#SGR-_query_O_O__ul_u5g_4gd_lpb}
{#SGR-_query_O_O__id_a3y_t5d_lpb__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Optional - 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. |
| value | String | Optional - must also specify a field parameter. Value to search for in the specified field parameter. |
[Table 118. Parameters]

{#SGR-_query_O_O__id_a3y_t5d_lpb} {#SGR-_query_O_O__table_whc_pcq_fz__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 119. Returns]

{#SGR-_query_O_O__table_whc_pcq_fz}  
The following example shows how query the Knowledge Feedback \[kb_feedback\] table and list
KB articles with comments that include Excel.

    var rec = new GlideRecord('kb_feedback');
    rec.addQuery('comments', 'CONTAINS', 'Excel');
    rec._query();
    while (rec.next()) { 
     gs.info(rec.getDisplayValue('article') + " comment: " + rec.getValue('comments'));
    }

Output:

    KB0000005 comment: 
    	     Can you please add the version of Excel this applies to? All?
    		
    KB0000005 comment: 
    	     Does this work for all Excel versions? OSX and Windows alike?

## Scoped GlideRecord - setAbortAction(Boolean b) {#ariaid-title62}

Sets a flag to indicate if the next database action (insert, update, delete) is to be
aborted. This is often used in business rules.
Use 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.
{#r_ScopedGlideRecordSetAbortAction_Boolean__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| b | Boolean | True to abort the next action. False if the action is to be allowed. |
[Table 120. Parameters]

{#r_ScopedGlideRecordSetAbortAction_Boolean__table_vy2_525_jq} {#r_ScopedGlideRecordSetAbortAction_Boolean__table_yv5_jtb_2r__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 121. Returns]

{#r_ScopedGlideRecordSetAbortAction_Boolean__table_yv5_jtb_2r}  

    // Often used in business rule to check whether the current operation should be aborted.
    if (current.size > 16) {
      current.setAbortAction(true);
    }

## Scoped GlideRecord - setLimit(Number maxNumRecords) {#ariaid-title63}

Sets the limit for number of records are fetched by the GlideRecord query.

Using setLimit() with chooseWindow()
:   The setLimit() method implicitly calls the chooseWindow() method and might cause unexpected results when used with chooseWindow() in a query.  
    * If the chooseWindow() method is called first, its record window is overwritten by the setLimit() method.  
      Using the following lines in a query returns 100 records starting at row 1:

          grIncident.chooseWindow(20,30);
          grIncident.setLimit(100);

    * If the setLimit() method is called first, the window set by chooseWindow() is used and the limit is overwritten.  
      Using the following lines in a query returns 10 records starting at row 21:

          grIncident.setLimit(5);
          grIncident.chooseWindow(20,30);

      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().
See also:

* [chooseWindow()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordChooseWindow_Number_Number_Boolean "Sets a range of rows to be returned by subsequent queries.")
* [query()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordQuery_Object_Object "Runs a query against the table based on the filters specified in the query methods such as addQuery() and addEncodedQuery().")
* [setNoCount()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#SGR-setNoCount "Stops a GlideRecord query from running a COUNT(*) query.")
{#r_ScopedGlideRecordSetLimit_Number__ul_zjw_cvd_xgc}
{#r_ScopedGlideRecordSetLimit_Number__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| maxNumRecords | Number | The maximum number of records to fetch. |
[Table 122. Parameters]

{#r_ScopedGlideRecordSetLimit_Number__table_vy2_525_jq}{#r_ScopedGlideRecordSetLimit_Number__table_owp_jtb_2r__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 123. Returns]

{#r_ScopedGlideRecordSetLimit_Number__table_owp_jtb_2r}  

    var now_GR = new GlideRecord('incident');
    now_GR.orderByDesc('sys_created_on');
    now_GR.setLimit(10);
    now_GR.query(); // this retrieves latest 10 incident records created

## Scoped GlideRecord - setNewGuidValue(String guid) {#ariaid-title64}

Sets the sys_id value for the current record.
{#r_ScopedGlideRecordSetNewGuidValue_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| guid | String | GUID to assign to the current record. |
[Table 124. Parameters]

{#r_ScopedGlideRecordSetNewGuidValue_String__table_vy2_525_jq} {#r_ScopedGlideRecordSetNewGuidValue_String__table_akk_jtb_2r__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 125. Returns]

{#r_ScopedGlideRecordSetNewGuidValue_String__table_akk_jtb_2r}  

    var now_GR = new GlideRecord('incident');
    now_GR.setValue('short_description', 'The third floor printer is broken');
    now_GR.setNewGuidValue('eb4636ca6f6d31005be8883e6b3ee333');
    now_GR.insert();
    gs.info(now_GR.getValue('sys_id'));

## Scoped GlideRecord - setNoCount() {#ariaid-title65}

Stops a GlideRecord query from running a `COUNT(*)` query.
Running 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.  
Note:  
The setLimit() method also stops a `COUNT(*)`. Using setNoCount() is unnecessary if the setLimit() method is included in the query.  
See also:

* [chooseWindow()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordChooseWindow_Number_Number_Boolean "Sets a range of rows to be returned by subsequent queries.")
* [query()](https://www.servicenow.com/docs/XnhzR4LTwK_VVBTm5Iii4g#r_ScopedGlideRecordQuery_Object_Object "Runs a query against the table based on the filters specified in the query methods such as addQuery() and addEncodedQuery().")
{#SGR-setNoCount__ul_zjw_cvd_xgc}
{#SGR-setNoCount__table_l12_f2x_1bc__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 126. Parameters]

{#SGR-setNoCount__table_l12_f2x_1bc} {#SGR-setNoCount__table_obb_bv4_2gb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 127. Returns]

{#SGR-setNoCount__table_obb_bv4_2gb}  
The following code example shows how to use setNoCount() to skip the `COUNT(*)` query on a windowed query set using the chooseWindow() method.

    var  grIncident = new GlideRecord('incident');

    grIncident.chooseWindow(6915, 6920, true);
    grIncident.setNoCount();
    grIncident.query();

    while (grIncident.next()) { // Iterate through the returned records
        gs.info('Incident Number: ' + grIncident.number + ', Short Description: ' + grIncident.short_description);
    };

Output:

    Incident Number: INC0006811, Short Description: Request an account to be created for Fidelity 401(k) Plans
    Incident Number: INC0006918, Short Description: Please grant me additional roles in Oracle Fin Collections
    Incident Number: INC0006812, Short Description: Taxware Value-added Tax crashes when I try to launch it
    Incident Number: INC0006919, Short Description: Unable to Access SuccessFactors Learning
    Incident Number: INC0010004, Short Description: Incident for assessment not generating

## Scoped GlideRecord - setValue(String name, Object value) {#ariaid-title66}

Sets the value of the field with the specified name to the specified value.
Normally 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.  
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://www.servicenow.com/docs/access?context=encryption-landing&version=zurich&pubname=zurich-platform-security&ft:locale=en-US).  

Not for authentication with password2 fields
:   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.

    For password2 authentication, use the setDisplayValue() method instead.  
    See also:

    * [Deprecate GlideEncrypter usage of 3DES for password2 fields](https://www.servicenow.com/docs/access?context=password2-3des-deprecation&version=zurich&pubname=zurich-platform-security&ft:locale=en-US)
    * [Alternatives to GlideEncrypter usage in knowledge base article KB1320986](https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1320986)
    * [Password2 encryption with the Key Management Framework (KMF)](https://www.servicenow.com/docs/access?context=password-2way-encrypted-fields&version=zurich&pubname=zurich-platform-security&ft:locale=en-US)
    {#r_ScopedGlideRecordSetValue_String_Object__ul_m1z_5js_12c}
{#r_ScopedGlideRecordSetValue_String_Object__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Name of the field. |
| value | Object | Value to assign to the field. |
[Table 128. Parameters]

{#r_ScopedGlideRecordSetValue_String_Object__table_vy2_525_jq} {#r_ScopedGlideRecordSetValue_String_Object__table_bp2_jtb_2r__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 129. Returns]

{#r_ScopedGlideRecordSetValue_String_Object__table_bp2_jtb_2r}  

    var elementName = 'short_description'; 
    var now_GR = new GlideRecord('incident'); 
    now_GR.initialize(); 
    now_GR.setValue(elementName, "My DB is not working");
    now_GR.insert();

## Scoped GlideRecord - setWorkflow(Boolean enable) {#ariaid-title67}

Enables or disables running business rules, script engines, or audits.
Note:  
The setWorkflow() method is ignored when subsequently using either the deleteProblem() or deleteMultiple() methods to cascade delete.  
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.  
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\&sysparm_article=KB0820691](https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0820691).
{#r_ScopedGlideRecordSetWorkflow_Boolean__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| enable | Boolean | Flag that indicates whether to enable or disable the running of business rules, script engines, and audit. Valid values: * true: Enables running business rules, script engines, or audits. * false: Disables running business rules, script engines, or audits. {#r_ScopedGlideRecordSetWorkflow_Boolean__ul_rb1_bwx_zqb} Default: true |
[Table 130. Parameters]

{#r_ScopedGlideRecordSetWorkflow_Boolean__table_vy2_525_jq} {#r_ScopedGlideRecordSetWorkflow_Boolean__table_cdx_3tb_2r__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 131. Returns]

{#r_ScopedGlideRecordSetWorkflow_Boolean__table_cdx_3tb_2r}  

    //Enable business rules, scripts engines for x_app_table
    var now_GR = new GlideRecord("x_app_table"); 
    now_GR.setWorkflow(true);

## Scoped GlideRecord - update(String reason) {#ariaid-title68}

Updates the GlideRecord with any changes that have been made. If the record does not
already exist, it is inserted.
{#r_ScopedGlideRecordUpdate_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| reason | String | Optional. Reason for the update. The reason appears in the audit record. |
[Table 132. Parameters]

{#r_ScopedGlideRecordUpdate_String__table_vy2_525_jq} {#r_ScopedGlideRecordUpdate_String__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Sys_id of the new or updated record. Returns null if the update fails. |
[Table 133. Returns]

{#r_ScopedGlideRecordUpdate_String__table_qpt_3f5_jq}  
The following example shows how to update the Short Description field of an incident.

    var now_GR = new GlideRecord('incident');
    now_GR.get('99ebb4156fa831005be8883e6b3ee4b9');
    now_GR.setValue('short_description', 'Update the short description');
    now_GR.update();
    gs.info(now_GR.getElement('short_description'));

Output:

    Update the short description.

## Scoped GlideRecord - updateMultiple() {#ariaid-title69}

Updates each GlideRecord in a stated query with a specified set of changes.
This method does not support adding multiple journal entries.

The 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://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=zurich&pubname=zurich-platform-administration&ft:locale=en-US).
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`.  
Note:  
Do not use this method with the chooseWindow() or setLimit() methods when working with large tables.

This 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://www.servicenow.com/docs/AoPZTdJPr1JHWoLt~BXO_w "GlideRecord variables (including current) are initially null in the database. Setting these back to an empty string, a space, or the JavaScript null value will not result in a return to this initial state.").
{#r_ScopedGlideRecordUpdateMultiple__table_qwk_ysb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 134. Parameters]

{#r_ScopedGlideRecordUpdateMultiple__table_qwk_ysb_2r} {#r_ScopedGlideRecordUpdateMultiple__table_fj2_htb_2r__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 135. Returns]

{#r_ScopedGlideRecordUpdateMultiple__table_fj2_htb_2r}  
This example shows how to update the state of all active incidents to 4 - "Awaiting User
Info".

    var now_GR = new GlideRecord('incident');
    now_GR.addQuery('active', true);
    now_GR.setValue('state',  4);
    now_GR.updateMultiple();

This example shows how to clear existing values of the description field for priority 1 incidents.

    var test = new GlideRecord('incident');
    test.addEncodedQuery('priority=1');
    test.query();
     
    test.setValue('description','NULL');
    test.updateMultiple();

## Scoped GlideRecord - updateWithReferences(Object reason) {#ariaid-title70}

Updates a record and also inserts or updates any related records with the information provided.
{#SGR-updateWithReferences_O__id_hhh_2fd_3zb__entry__3}

| Name | Type | Description |
|-|-|-|
| reason | Object | Reason for the updates. The reason is displayed in the audit record. |
[Table 136. Parameters]

{#SGR-updateWithReferences_O__id_hhh_2fd_3zb} {#SGR-updateWithReferences_O__id_l3b_ffd_3zb__entry__2}

| Type | Description |
|-|-|
| String | The sys_id for the record being updated. |
[Table 137. Returns]

{#SGR-updateWithReferences_O__id_l3b_ffd_3zb}  
If 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.

    var inc = new GlideRecord('incident');
    inc.get(inc_sys_id);  // Looking up an existing incident record where 'inc_sys_id' represents the sys_id of a incident record
    inc.caller_id.first_name = 'John';
    inc.caller_id.last_name = 'Doe';
    inc.updateWithReferences();
    }


