How to add Or condition with Null

ericpan
Kilo Explorer

Hi,

I can use addNotNullQuery or addNullQuery on a field as a filter. I can use addOrCondition to add a Or condition on a field. However, how can I add a Null Or condition on a field? For example, field1 = '123' or field1 IS Null.

Thanks,

Eric

8 REPLIES 8

Mike Allen
Mega Sage

You can also do:



var gr = new GlideRecord('table');


gr.addQuery('field', 'value1').addOrCondition('field', '');


gr.query();



while (gr.next()) {


//code here


}


http://wiki.servicenow.com/index.php?title=Setting_a_GlideRecord_Variable_to_Null#gsc.tab=0



From this, my guess is you can say:



.addOrCondition('field', 'NULL');




Tested in my developer instance and this does work.




var inc = new GlideRecord('incident');


inc.addQuery('caller_id', 'NULL');


inc.query();


gs.print(inc.getRowCount());




This returned 16 records in the instance, which is the number of incidents with no caller_id value.


Thank you very much for all of you. I will try your suggestions.


MGanon
Tera Guru

Have you tried this?

var gr = new GlideRecord('table_name');
gr.addNullQuery('field');
gr.addOrCondition('field', 'value');

This approach looks for NULL or value.
(Separately, I would like to query for field1 is NULL --OR-- field2 is NULL but I don't know the syntax to add multiple NULL queries.)