---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideQueryCondition - Scoped

# GlideQueryCondition - Scoped {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

The scoped GlideQueryCondition API provides additional `AND` or `OR` conditions that can be added to the current condition, allowing you to build complex queries.  
Build complex queries such as:

    category='hardware' OR category='software' AND priority='2' AND priority='1'

In the case of addCondition(), an implied `AND` is added.  
This class has no constructor. A GlideQueryCondition object is returned by the following methods:

* addActiveQuery()
* addInactiveQuery()
* addJoinQuery()
* addNotNullQuery()
* addNullQuery()
* addQuery()
{#c_GlideQueryConditionScopedAPI__ul_xyz_nsg_qz}

If there is a complicated set of `AND` and `OR` queries, a single encoded query containing all conditions simplifies the query creation. To simplify the query creation, create a query in a list view,
right-click the query, and select Copy query. It creates a single encoded query string to return your result set. Use that string as a parameter in an addEncodedQuery() call.

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=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US).

## GlideQueryCondition - addCondition(String name, String oper, Object value) {#ariaid-title2}

Adds an AND condition to the current condition.
{#r_ScopedGlideQueryConditionAddCondition__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Name of a field. |
| oper | String | Optional. The operator for the query. If you do not specify an operator, the condition uses an equals operator. |
| value | Object | Value to query on. |
[Table 1. Parameters]

{#r_ScopedGlideQueryConditionAddCondition__table_vy2_525_jq}  
{#r_ScopedGlideQueryConditionAddCondition__table_mxx_f5b_2r__entry__2}

| Type | Description |
|-|-|
| GlideQueryCondition | Reference to a GlideQueryConditon that was added to the glide record. |
[Table 2. Returns]

{#r_ScopedGlideQueryConditionAddCondition__table_mxx_f5b_2r}  

    var now_GR = new GlideRecord('incident');
    var qc = now_GR.addQuery('category', 'Hardware');
    qc.addCondition('category', 'Network');
    now_GR.addQuery('number','INC0000003');
    now_GR.next();
    now_GR.number;
    gs.info(now_GR.getEncodedQuery());

## GlideQueryCondition - addOrCondition(String name, String oper, Object value) {#ariaid-title3}

Appends a two-or-three parameter OR condition to an existing
GlideQueryCondition.
addOrCondition() works in conjunction with any of the [addQuery()](https://servicenow-prod.fluidtopics.net/Z64TK~kWnpWTEG5bCPvZuQ#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.") methods to `OR` the specified query parameters to the query previously
constructed using addQuery().

addOrCondition() is typically called with three parameters; table field,
operator, and comparison value. It can be called with only two parameters, table field and
comparison value, such as `qc.addOrCondition('category', 'software');`. The
operator in this case is assumed to be "equal to".  
{#r_ScopedGlideQueryConditionAddOrCondition__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Field name |
| oper | String | (Optional) Query operator. The available values are dependent on the data type of the <var class="keyword varname">value</var> parameter. Numbers: * = * != * \> * \>= * \< * \<= {#r_ScopedGlideQueryConditionAddOrCondition__ul_qyb_rbt_3y} Strings (must be in upper case): * = * != * IN * STARTSWITH * ENDSWITH * CONTAINS * DOESNOTCONTAIN {#r_ScopedGlideQueryConditionAddOrCondition__ul_egz_vbt_3y} |
| value | Object | Value on which to query (not case-sensitive). Note: All passed in arrays must contain a minimum of two elements. Single element arrays are not supported. |
[Table 3. Parameters]

{#r_ScopedGlideQueryConditionAddOrCondition__table_vy2_525_jq}  
{#r_ScopedGlideQueryConditionAddOrCondition__table_w2h_w2c_2r__entry__2}

| Type | Description |
|-|-|
| GlideQueryCondition | A reference to a GlideQueryConditon that was added to the GlideRecord. |
[Table 4. Returns]

{#r_ScopedGlideQueryConditionAddOrCondition__table_w2h_w2c_2r}  

    var now_GR = new GlideRecord('incident');
    var qc = now_GR.addQuery('category', 'Hardware');
    qc.addOrCondition('category', 'Network');
    now_GR.addQuery('number','INC0000003');
    now_GR.next();
    now_GR.number;
    gs.info(now_GR.getEncodedQuery());

To group AND/OR statements to make complex queries, such as "All incidents with a (state
less than 3 OR greater than 5) AND (priority is 1 OR priority is 5)

    var myObj = new GlideRecord('incident');
    var q1 = myObj.addQuery('state', '<', 3);
    q1.addOrCondition('state', '>', 5);
    var q2 = myObj.addQuery('priority', 1);
    q2.addOrCondition('priority', 5);
    myObj.query();


