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

Mark Roethof
Tera Patron
Tera Patron

Hi there,

You are mentioning GlideRecord but I see current? Or is this for a query Business Rule for example, to limit the query, then this could be fine. Not sure, but maybe addNullQuery / addNotNullQuery will work there also?

See examples from GlideRecord below.

find_real_file.png

find_real_file.png

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

It's a relationship for a related list. Ohh I think that'll work let me check and then get back to you

 

I tried nullquery on the fields and it returns nothing

find_real_file.png

find_real_file.png

 

Then I tried NotNull, but it seems to not have done anything

find_real_file.png

 

find_real_file.png

 

 

 

 

 

Hi there,

Just tested. Technically the addQuery and multiple addQuery should work fine.

I just tested with a before Query Business Rule with below code, no issues.

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

	current.addQuery('urgency', 1);
	current.addQuery('category', '!=', '');
	current.addQuery('u_test_date', '!=', '');
	current.addActiveQuery();
	
})(current, previous);

How is your Business Rule looking like completely?
And have you tested the different queries also separately, to see which one might not be working and causing the issue?

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