How to extract a complete list of CI Classes available in ServiceNow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2012 02:00 AM
Hi,
I need to extract all CI classes available in ServiceNow (OOB) no matter if these classes contain any data or not. I just need to extract the whole available list.
I am trying to set a filter on sys_db_object table yet not come up with the expected result.
Please give your input.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2023 12:52 AM
This is stored in CMDB_CLASS_INFO table along with principal class indicator (I've been searching for this too!).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2023 10:38 PM
To extract all CI classes available in ServiceNow, you can query the "cmdb_ci" table in ServiceNow. This table contains all the CI classes that are available in the instance.
To get a list of all the CI classes available, you can use the following GlideRecord query:
csharp
Copy code
var ciClassGR = new GlideRecord('cmdb_ci');
ciClassGR.query();
while (ciClassGR.next()) {
var className = ciClassGR.getValue('sys_class_name');
gs.info(className);
}
This query will iterate through all the records in the "cmdb_ci" table and print out the value of the "sys_class_name" field, which contains the name of the CI class.
Note that the "cmdb_ci" table may contain a large number of records, so you may want to consider adding a filter to limit the number of records returned. For example, you could add a filter to exclude retired CI classes:
csharp
Copy code
var ciClassGR = new GlideRecord('cmdb_ci');
ciClassGR.addQuery('sys_class_name', 'NOT IN', 'Retired');
ciClassGR.query();
while (ciClassGR.next()) {
var className = ciClassGR.getValue('sys_class_name');
gs.info(className);
}
This will only return CI classes that are not retired. You can modify the filter as needed to exclude or include other types of CI classes.
Regards,
Rachel Gomez