The CreatorCon Call for Content is officially open! Get started here.

Background script returns 0 count for table

ServiceNowVS
Tera Expert

Hi Team,

 

I am facing a very weird issue. I am trying to get count of records in a table using background script. However i am getting count as 0. even though there are data in that table. This is happening in DEV instance., Working fine in other instances. Here is my script:

 

var getCount = new GlideRecord('<<tablename>>');
getCount.addQuery('sys_id', <<sys_id>>);
getCount.query();
gs.print("Count is  "+ getCount.getRowCount());
 
Even if i dont put query condition in line 2, in every case count is coming as 0.
 
There are ACL's restricting data but that should not affect getting counts from backend right? Tried fix script too.
 
Anybody else faced this?
9 REPLIES 9

Sandeep Rajput
Tera Patron
Tera Patron

@ServiceNowVS You mentioned that the script is working fine on other instances, are you sure about the sys_id used in the addQuery here, did you check if the sys_id used in addQuery actually exists on your table in DEV instance?

Hi Sandeep,

 

even if i dont put sys_id , still it is showing 0 records.

var getCount = new GlideRecord('<<tablename>>');
getCount.query();
gs.print("Count is  "+ getCount.getRowCount());
 
This is also returning 0..

Sal12
Tera Expert

That means, the query did not return anything. Did you check if the sys_id exists on that table?

Do you get any other output on the right side, would you be able share that output?

Hi @Sal12 ,

 

Here you go:

ServiceNowVS_0-1700248512760.png

 

Is the table name correct? What kind of table are you querying? Is it a database view? After verifying that, could you remove everything below getCount.query();

 

and instead type gs.info("Count = " + getCount.getRowCount());