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:35 AM
Check if you are passing the table name and sysid properly. Your sysid should be 32 chars UID (count it).
Alternate approach:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 10:24 AM
Hi Shubham,
Yes i have tried the same script in QA instance and it is giving me count. Even though i dont query certain sys_id, it is still giving count as 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 09:36 AM
Hi @ServiceNowVS ,
If you're facing an issue where you're unable to retrieve records count using a GlideRecord query despite having data in the table, it could be due to various reasons. Here are a few things to check and consider:
1. **Permissions & ACLs:**
- Ensure that the user executing the script has sufficient permissions to access the table and read the records.
- Check the ACLs (Access Control Lists) on the table. Even though ACLs shouldn't directly affect retrieving counts, it's worth reviewing them to ensure they're not causing unexpected behavior.
2. **Instance-specific Issues:**
- Check for any instance-specific configurations or customizations that might impact data retrieval.
- Compare the configurations between the working instances and the problematic one. Differences might give clues about the issue.
3. **Cache or Indexing:**
- Check if there are any issues related to indexing or cache. Sometimes, issues in indexing can lead to unexpected results in record retrieval.
- Try clearing the cache or re-indexing the table to ensure data is accurately reflected.
4. **Error Handling:**
- Check for any errors or exceptions in the script execution by adding error handling.
Here's an updated version of your script with error handling to identify any potential issues:
var getCount = new GlideRecord('<<tablename>>');
getCount.addQuery('sys_id', '<<sys_id>>'); // Replace <<tablename>> and <<sys_id>> with actual values
getCount.query();
if (getCount.error()) {
gs.print("Error retrieving records: " + getCount.getErrorMessage());
} else {
gs.print("Count is " + getCount.getRowCount());
}
This script includes error handling to print an error message if there's an issue with the query execution.
If the issue persists, consider reaching out to your ServiceNow instance administrator or support team to investigate further, as this could be related to instance-specific configurations or issues.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 10:31 AM
Hi Danish,
All the configurations are same for DEV & QA instance.
I have tried to run the updated version and it is going to else part and printing count as 0