- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 05:06 AM
Hi ServiceNow Community,
I have an issue with the code below when running in a background script.
var child_so_list = ['61faa1851bf6c8d0a7c2b8c2cd4bcbe0','1dfaa1851bf6c8d0a7c2b8c2cd4bcb1d','0dfaa1851bf6c8d0a7c2b8c2cd4bcb1a'... 342 sys id in the list ];
var company_sys_id = '4bbf4192db2beb8088065487dc96199b';
var gr_so = new GlideRecord('service_offering');
gr_so.addQuery('company', '=', company_sys_id);
gr_so.addQuery('sys_id' ,'IN' , child_so_list.toString());
gr_so.query();
gs.print(gr_so.getRowCount());
There is only one service offering in the array that has company as the one queried. And so it should only return 1 but the query is returning 342 (the number of sys id's in the array). I then ran this second script to try and see if it was to do with the number of sys id's in the array.
var child_so_list = ['61faa1851bf6c8d0a7c2b8c2cd4bcbe0','1dfaa1851bf6c8d0a7c2b8c2cd4bcb1d','0dfaa1851bf6c8d0a7c2b8c2cd4bcb1a','b0fa61851bf6c8d0a7c2b8c2cd4bcb4e'... 342 sys id in the list];
var so_count = child_so_list.length
for(var i = 0;i<so_count;i++){
var company_sys_id = '4bbf4192db2beb8088065487dc96199b';
var gr_so = new GlideRecord('service_offering');
gr_so.addQuery('company', '=', company_sys_id);
gr_so.addQuery('sys_id' ,'IN' , child_so_list.toString());
gr_so.query();
gs.print(gr_so.getRowCount());
child_so_list.pop();
}
And with this script when the array gets down to 100 items it starts to correctly return the row count. Is there a limit on the number of items you can have in an array for getRowCount to work. After speaking with a colleague they suggested I use the below line instead of the getQuery lines.
gr_so.addQuery('company', '4bbf4192db2beb8088065487dc96199b').addCondition('sys_id', 'IN', child_so_list.toString());
And this works regardless of how many items are in the array.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 03:11 AM
This is a known bug in ServiceNow - PRB1638779- getRowCount() on GlideRecord is returning incorrect value.
They provided the workaround of - If you dont need to iterate through the results and just wants to get a count, you can use
GlideAggregate getAggregate()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 03:11 AM
This is a known bug in ServiceNow - PRB1638779- getRowCount() on GlideRecord is returning incorrect value.
They provided the workaround of - If you dont need to iterate through the results and just wants to get a count, you can use
GlideAggregate getAggregate()