- 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
‎03-19-2025 07:43 AM
GlideTableHierarchy API is for scoped application. Do we have any API for global scope? OR Can we use INSTANCEOF operator to get all parent or child class names
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2019 03:41 AM
Thanks for the reply Deepak, but I am not looking for the class of the object. I want to know if the object is a subclass of another class. For example, in a legacy application I can instantiate a GlideRecord of class Computer:
computerCI = new GlodeRecord("ci_cmdb_computer");
computerCI.addQuery"SOME NAME");
computerCI.query();
After this the following calls both return "true" because Computer is a subclass of Hardware:
computerCI.instanceOf("cmdb_ci_computer");
computerCI.instanceOf("cmdb_ci_hardware");