GlideRecord - addDomainQuery(Object glideRecord)

Changes the domain used for the query from the user's domain to the domain of the provided GlideRecord.

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.

Table 1. Parameters
Name Type Description
glideRecord Object GlideRecord from which to obtain the domain.
Table 2. Returns
Type Description

Scoped equivalent

This method is not available in scoped applications.

//This example requires the Domain plugin be active, the Group table is the specified 
//Domain table, and the ITIL user is in the Database Atlanta domain
//From any domain (using queryNoDomain()) look up the incidents that an ITIL user can only see 
//who is in the Database Atlanta domain, should expect all incidents with the global or the
//Database Atlanta domain specified.
var domain = new GlideRecord('sys_user');
domain.addQuery('user_name', 'itil');
if ( {
    var domainQuery = new GlideRecord('incident');
    domainQuery.addQuery('active', true);
    gs.print('Number of Incidents for ITIL user: ' + domainQuery.getRowCount());
    while (