How to apply "field is not empty" in GlideRecord addCondition?

PhoenixMing0912
Giga Expert

Hi all,

I want to seach a non-empty String field in a table by using addCondition.

I went through the following tutorial:

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server_legacy/c_GlideQueryConditionAPI

 

But looks like xx != ""  is not working. Anyone could help?

9 REPLIES 9

Willem
Giga Sage
Giga Sage

To check if it is not empty use:

.addNotNullQuery();

You can try using it instead of addCondition like this:

var gr = new GlideRecord('incident');
var qc = gr.addQuery('category', 'Hardware');
qc.addNotNullQuery();
gr.addQuery('number', 'INC0000003');
gr.next();
gr.number;
gs.info(gr.getEncodedQuery());

 

If you can share the query you are building, we can help apply it to that. In some cases even below will suffice:

var gr = new GlideRecord('incident');
gr.addQuery('category', 'Hardware');
gr.addNotNullQuery();
gr.addQuery('number', 'INC0000003');
gr.next();
gr.number;
gs.info(gr.getEncodedQuery());

 

Dhananjay Pawar
Kilo Sage

Hi,

Try to use encoded query.

gr.addEncodedQuery('short_descriptionISNOTEMPTY');

 

Thanks,

Dhananjay.

For example check below attached screenshot.

find_real_file.png

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can either use notNullQuery or use the encoded query

short_descriptionISNOTEMPTY

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader