How to apply "field is not empty" in GlideRecord addCondition?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2020 09:08 PM
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?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2020 09:17 PM
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());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2020 09:37 PM
Hi,
Try to use encoded query.
gr.addEncodedQuery('short_descriptionISNOTEMPTY');
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2020 09:40 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2020 09:39 PM
Hi,
you can either use notNullQuery or use the encoded query
short_descriptionISNOTEMPTY
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader