Need number of record for all tables with name containing "cmdb"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 01:20 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 01:49 AM - edited 12-07-2023 01:52 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 01:59 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 02:16 AM
Hi @shessdri
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 02:13 AM
@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);
}
}