Available JavaScript operators

The table below contains the operators that can be supplied to the addQuery() request.

Table 1. Available JavaScript Operators
Field Definition addQuery
= Field must be equal to value supplied. addQuery('priority', '=', 1);
> Field must be greater than value supplied. addQuery('priority', '>', 1);
< Field must be less than value supplied. addQuery('priority', '<', 3);
>= Field must be equal or greater than value supplied. addQuery('priority', '>=', 1);
<= Field must be equal or less than value supplied. addQuery('priority', '<=', 3);
!= Field must not equal the value supplied. addQuery('priority', '!=', 1);
STARTSWITH Field must start with the value supplied. The example shown on the right will get all records where the short_description field starts with the text Error. addQuery('short_description', 'STARTSWITH', 'Error');
CONTAINS Field must contain the value supplied somewhere in the text. The example shown on the right will get all records where the short_description field contains the text Error anywhere in the field. addQuery('short_description', 'CONTAINS', 'Error');
IN Takes a map of values that allows commas, and gathers a collection of records that meet some other requirement. Behaves as Select * from <table> where short_description IN ('Error'), which is identical to Select * from <table> where short_description='Error'. For example, to query all variable values that belong to a specific Activity, use the IN clause to query all Activities that are of that type, and store their sys_ids in a map, or comma-separated list. Then query the variable value table and supply this list of sys_ids. addQuery('short_description', 'IN', 'Error,Success,Failure');
ENDSWITH Field must terminate with the value supplied. The example shown on the right will get all records where the short_description field ends with text Error. addQuery('short_description', 'ENDSWITH', 'Error');
DOES NOT CONTAIN Selects records that do NOT match the pattern in the field. This operator does not retrieve empty fields. For empty values, use the operators "is empty" or "is not empty". The example shown on the right will get all records where the short_description field does not have the word "Error". addQuery('short_description', 'DOES NOT CONTAIN', 'Error');
NOT IN Takes a map of values that allows commas, and gathers a collection of records that meet some other requirement. Behaves as: Select * from <table> where short_description NOT IN ('Error'). addQuery('short_description', 'NOT IN', 'Error,Success,Failure');
Special operator that allows you to retrieve only records of a specified "class" for tables which are extended. For example when going after configuration items (cmdb_ci table) you many want to retrieve all configuration items that are have are classified as computers. The code to the right will do that. addQuery('sys_class_name', 'INSTANCEOF', 'cmdb_ci_computer');
There are also some special methods that can be used when you want to search for data that is NULL or NOT NULL. To search for all incidents where the short_description field has not been supplied (is null), use the following query:
var target = new GlideRecord('incident'); 
target.addNullQuery('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 
}
To find all incidents in which a short_description has been supplied, use the following query:
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 
}

For additional information see GlideRecord.