GlideRecord - addNotNullQuery(String fieldName)

Adds a filter to return records where the specified field 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.

Table 1. Parameters
Name Type Description
fieldName String The field name.
Table 2. Returns
Type Description
QueryCondition QueryCondition of records where the parameter field is not null.

Scoped equivalent

To use the addNotNullQuery() method in a scoped application, use the corresponding scoped method: Scoped GlideRecord - addNotNullQuery(String fieldName).

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