- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 02:27 PM
Hi Guys,
I am working on one requirement, which is finding the no.of empty tables in servicenow (no records).
What is the best way so that I can get them by script or filters, and I wanted to generate the report as well.
please help me.
thanks in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 03:39 PM
Here is the script that gives you the list of tables with 0 records
var tble = new GlideRecord('sys_db_object');
tble.addEncodedQuery('sys_update_nameISNOTEMPTY^name!=v_wf_validation_report^nameISNOTEMPTY');
tble.query();
var count = 0;
while(tble.next()){
var gr = new GlideRecord(tble.name);
if(gr.isValid()){
gr.query();
if(gr.getRowCount() == 0){
gs.log('Table Name: ' + tble.name);
count++;
}
}
}
gs.log('Total Tables:' +count);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 02:38 PM
Hi,
Do you have a specific list of Tables where you want to do this operation or you are planning to query all the Tables in Service Now(which I would not recommend). Please confirm or elaborate on your requirement.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 03:39 PM
Here is the script that gives you the list of tables with 0 records
var tble = new GlideRecord('sys_db_object');
tble.addEncodedQuery('sys_update_nameISNOTEMPTY^name!=v_wf_validation_report^nameISNOTEMPTY');
tble.query();
var count = 0;
while(tble.next()){
var gr = new GlideRecord(tble.name);
if(gr.isValid()){
gr.query();
if(gr.getRowCount() == 0){
gs.log('Table Name: ' + tble.name);
count++;
}
}
}
gs.log('Total Tables:' +count);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 03:57 PM
Thank you for the quick reply, currently I am working on rest end points, so other environments some time having empty tables, in that case my rest points getting failure at testing, and my manager wanting to know how many no.of empty tables we have in lower environments. I will use this script in fix script part so that I can get the list of tables.
Thanks Sir,
i will test this script and let you know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2019 07:23 AM
Thanks its working fine for me.