Table Row Count

Amit Singh1
Tera Contributor

Hi,

How to row counts for each table in servicenow

Please give me solution

1 ACCEPTED SOLUTION

Rahul Kumar17
Tera Guru

Hi Amit 

U r going to this link

https://community.servicenow.com/community?id=community_blog&sys_id=19ace225dbd0dbc01dcaf3231f961948

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

View solution in original post

7 REPLIES 7

Abhishek Pidwa
Kilo Guru

Hi , 

 

Do you need it for specific tables or all of the tables ? 

 

1) if all the tables, then you have to query the sys_db_object (where all the tables are stored) to get the table names.

 

2) For each table name , query the glide record and get the desired row count by using getRowCount()

 

var gr = new GlideRecord('sys_db_object');

gr.query();

 

while (gr.next()){

  var grTable = new GlideRecord(gr.name);

  grTable.query();

  grTable.getRowCount();

gs.addInfoMessage("Table "+gr.label+ " has these many rows: "+grTable.getRowCount());

 

}

 

This query would take a lot of time since it is querying all the tables. If you want specific tables then you can assign the conditions in the filter section. gr.AddQuery(?,?)

 

Let me know how it goes.

 

Please mark this answer as correct/helpful if this solves your problem

hi

count all table row not particular table 

Yeah so if you want to count table row then use grTable.getRowCount(); . Is that not what you want ? Can you explain your requirements with an example ? 

like 

incident table,problem table,change table etc.

count all row in incident,problem,etc