Need number of record for all tables with name containing "cmdb"

shessdri
Tera Contributor

Hi Team,

 

I have a requirement to get the records corresponding to each table containing cmdb in name

 

As in I have 1400 tables whose name contains cmdb, I want info for each table separately , like how many records each table is having.
Can anyone help me with the code OR filter corresponding to this.

 

Thanks.

11 REPLIES 11

Anand Kumar P
Giga Patron
Giga Patron

Hi @shessdri ,

You have to glide record cmdb table parent for all classes

var cmdbRecord = new GlideRecord('cmdb');

cmdbRecord.addQuery('name', 'CONTAINS', 'cmdb');

//cmdbRecord.addQuery('sys_class_name','cmdb_ci_server')--for getting records for each individual class server

while (cmdbRecord.next()) {
var ciname= cmdbRecord.getValue('name');

gs.info('CI Name '+ ciname);
}

 

Mark it helpful and solution proposed if it serves your purpose.

Thanks,

ANAND

Hi Anand,


We are looking for tables whose name contains cmdb not the Cis containing name as cmdb.

Need number of record for all 1400 tables with name containing "cmdb", individually, each table contains how many records.

 

Thanks.

Hi @shessdri 

 

LearnNGrowAtul_0-1701944145032.pngLearnNGrowAtul_1-1701944165533.png

LearnNGrowAtul_2-1701944182938.png

 

 

As per list view, these 3 ways are there but when we use contains word it can be many. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Akshata T
Tera Guru

@shessdri  Try below code you will get count of records as per the tables containing 'cmdb' in name.

 

var getTables = new GlideRecord('sys_db_object');
getTables.addEncodedQuery('nameLIKEcmdb');
getTables.query();
while(getTables.next()){
var tablesName = getTables.name;
var glideEachTable = new GlideRecord(tablesName);
glideEachTable.query();
if(glideEachTable.next()){
var rowCount = getTables.name + ':' + glideEachTable.getRowCount();
gs.info(rowCount);
}
}