Efficient way to return record counts against selected tables...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-28-2024 04:27 AM
I'm extracting data out of ServiceNow for around 100+ tables. I then need to roughly compare the counts to prove the extraction hasn't missed any records. I do this currently by making a Rest API Explorer request for each of the tables and taking the X-Total-Count.
There must be a more efficient way I can do this. Anyone have any suggestions?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-28-2024 04:39 AM - edited ā02-28-2024 04:42 AM
How about using a common function for GlideAggregate and getting the count
function getRecordCount(tableName) {
var gr = new GlideAggregate(tableName);
gr.addAggregate('COUNT');
gr.query();
if (gr.next()) {
return gr.getAggregate('COUNT');
}
return 0; // Return 0 if no records found
}
Sample - replace table names
var table1Count = getRecordCount('table1');
var table2Count = getRecordCount('table2');
// ... Repeat for other tables
gs.info('Table 1 record count: ' + table1Count);
gs.info('Table 2 record count: ' + table2Count);
// ... Log counts for other tables
Run in the background with required table names and it should easily get you all the counts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-28-2024 04:48 AM
you can also use Aggregate API
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader