The CreatorCon Call for Content is officially open! Get started here.

How to find no.of empty (no records) tables in servicenow?

Kumar26
Tera Contributor

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. 

 

1 ACCEPTED SOLUTION

dvp
Mega Sage

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);

View solution in original post

4 REPLIES 4

shloke04
Kilo Patron

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

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

dvp
Mega Sage

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);

Kumar26
Tera Contributor

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. 

Kumar26
Tera Contributor

Thanks its working fine for me.