Background script returns 0 count for table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 09:24 AM
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:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 09:41 AM
@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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 10:21 AM
Hi Sandeep,
even if i dont put sys_id , still it is showing 0 records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 11:06 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 11:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 11:34 AM
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());