How to add Or condition with Null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2015 12:13 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2015 04:39 AM
You can also do:
var gr = new GlideRecord('table');
gr.addQuery('field', 'value1').addOrCondition('field', '');
gr.query();
while (gr.next()) {
//code here
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2015 04:42 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2015 11:38 AM
Thank you very much for all of you. I will try your suggestions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2019 08:14 AM
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.)
