Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Ken83
Mega Guru

I would do one condition with the addOrCondition and follow that up with the nullQuery like so...



var gr = new GlideRecord('table_name');


gr.addQuery('field', 'value');


gr.addOrCondition('field', 'value');


var q = gr.addNullQuery('field', value);


gr.query();



Not even sure if that'll work but it's the first thing that came to mind...


or even try



var gr = new GlideRecord('table_name');


gr.addQuery('field', 'value');


gr.addOrCondition('field', 'value');


var q = gr.addOrCondition('field', 'value');


gr.query();


Anurag Tripathi
Mega Patron
Mega Patron

var gr = new GlideRecord('');


var qc = gr.addQuery('field', 'value1');


qc.addOrCondition('field', 'value2');


gr.query();


while (gr.next()) {


//do your stuff


}


-Anurag

rajesh888
Kilo Explorer

Hope this helps




var x = null;


var a= new GlideRecord(tablename);


var b= a.addQuery('fieldname', '123');


b.addOrCondition('fieldname1', 'x');


a.query();


while (a.next()) {


.....


}