- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2019 06:08 AM
I need to do the equivalent of gr.instanceOf("cmdb_ci_hardware") in a scoped application. The only thing I can come up with is something like this:, which does not seem very efficient. Is there a better way? I am trying to see if a CI is in the Hardware class or any of its subclasses (e.g. Computer).
Bonus question: why is instanceOf missing in the scoped API?
_isHardware: function(ci){
var related = new GlideRecord("cmdb_ci_hardware");
related.addQuery("sys_id", ci.sys_id);
related.addActiveQuery();
related.setLimit(1);
related.query();
if ( related.next() ) {
return true;
}
else {
return false;
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2019 05:25 PM
Check out Scoped GlideTableHierarchy
var table = new GlideTableHierarchy("cmdb_ci_computer");
var tables = table.getHierarchy();
var isHardware = (tables.indexOf("cmdb_ci_hardware") > 0);
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2019 07:24 AM
Hi,
You can use getRecordClassName() method to return the class of the CI.
Now, why it is not working in scoped app, only ServiceNow can answer it. But you have the above alternative what you can go with.
Note: Please mark reply as correct / helpful if it has answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2019 12:17 PM
Thanks for the response Deepak, but I am not looking for the class. I am trying to find out whether the CI is a subclass of another. For example in a legacy application, taking a CI of class Computer, instanceOf("cmdb_ci_hardware") will return true because Computer is a subclass of Hardware.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2019 05:25 PM
Check out Scoped GlideTableHierarchy
var table = new GlideTableHierarchy("cmdb_ci_computer");
var tables = table.getHierarchy();
var isHardware = (tables.indexOf("cmdb_ci_hardware") > 0);
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2019 11:07 AM
Perfect Paul. I missed that one. Thanks.