addnotNullQuery/addNullQuery is not working on GlideRecord

Shivam32
Tera Contributor

I have written below background script to check how many records are returned but everytime it is returning count.

In the below script this record has no photo attached so it should return row count as 1 but it is not showing any result.

 

var user = new GlideRecord('live_profile');
user.addNullQuery('photo');
user.addQuery('sys_id', '566ec9ca83d56ghhbccb3d57709af19fc');
user.query();
if(user.next()) {
var countPA = user.getRowCount();
gs.print("countPA" +countPA);
}

3 REPLIES 3

Anurag Tripathi
Mega Patron
Mega Patron

HI, 

Try this

var usr = new GlideRecord('live_profile');
usr.addNotNullQuery('photo');
usr.addQuery('sys_id', '566ec9ca83d56ghhbccb3d57709af19fc');
usr.query();
gs.print("countPA" +usr.getRowCount());

 Since you have queries on a sys_id, the row count will be 1 or 0 

-Anurag

I tried but everytime it is returning 1 even if the photo is not there.

Try this

var usr = new GlideRecord('live_profile');
usr.addQuery('photo', '!=', '');
usr.addQuery('sys_id', '566ec9ca83d56ghhbccb3d57709af19fc');
usr.query();
gs.print("countPA" +usr.getRowCount());

 

If that doesn't work then from the list view of the table filter the record with photo as none or blank or null. And then use that in the encoded query.  

-Anurag