How to query out fields that have an empty value with GlideRecord?

Mitch Moses
Giga Expert

I tried this and it didn't work

current.addQuery('location', '!=', "");
current.addQuery('cmdb_ci', '!=', "");
10 REPLIES 10

Just tested with below code on Incident related list. No issues 😞 Only records with cmdb_ci are shown.

(function executeRule(current, previous /*null when async*/) {

// 	current.addQuery('cmdb_ci', '!=', '');
	current.addNotNullQuery('cmdb_ci');
	
})(current, previous);

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Steven Herrmann
Giga Guru

Hey Mitch,

I believe using an encoded query will work for this.

Something like the below for example:

current.addEncodedQuery('locationISEMPTY^cmdb_ciISEMPTY');

If my reply helps you at all, I'd really appreciate it if you click the Helpful button and if my reply is the answer you were looking for, it would be awesome if you could click the Accepted Solution button!  🙂

I hope this helps, have a great day!

Steve

Ah that's a nice thought too!

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

I tried this one and went to another ticket that has some empty and some filled ones, but it gets rid of all of them 

find_real_file.png

 

find_real_file.png

 

 

 

 

 

 

 

 

Mitch Moses
Giga Expert

This is so weird. So without trying anything you guys suggested I get this: 23 incidents 

find_real_file.png

And this for another incident: 9 incidents

 

find_real_file.png

 

Now when I add current.addQuery('cmdb_ci', '!=', "NULL"); or current.addNotNullQuery('cmdb_ci'); It gets rid of the empties in one incident, but not the other one??

21 incidents now:

find_real_file.png

 

9 incidents still: 

find_real_file.png

 

 Maybe this one incident is bugged?