What's the opposite of INSTANCEOF?

grosch
Mega Expert

I have a given class name, such as 'cmdb_ci_linux_server'.   Now I want to find all the cmdb_model entries that would be a valid choice for an asset of type cmdb_ci_linux_server, so I started off like so:

var gr = new GlideRecord('cmdb_model');

gr.addQuery('status', '!=', 'Retired');

gr.addNotNullQuery('name');

gr.addQuery('cmdb_ci_class', 'INSTANCEOF', 'cmdb_ci_linux_server');

gr.query();

But that INSTANCEOF is backwards.   Is there a way to flip that around?   So basically I want to return all models where the cmdb_ci_class belongs to a table that cmdb_ci_linux_server inherits from.   I want a PARENTOF type qualifier

Is there an easy way to do that, or do I just have to use TableUtils() and manually build up a big or statement?

3 REPLIES 3

The SN Nerd
Giga Sage
Giga Sage

Unless there is a undocumented operator that someone is privy to, you'll have to use TableUtils()



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

James Fricker
Tera Guru

I would do it this way

var gr = new GlideRecord('cmdb_model');
gr.addQuery('status', '!=', 'Retired');
gr.addNotNullQuery('name');
gr.addQuery('cmdb_ci_class', 'IN', j2js(GlideDBObjectManager.get().getTables('cmdb_ci_linux_server')));
gr.query();

 

Rafał Rataj
Tera Contributor

 

RafaRataj_1-1741169269741.png

you can use the class path 

 

var childClass = gr.child.sys_class_path.toString();
            if (childClass.startsWith("/!!/!2/!(/!!")){ // is Instance of server
                children.push(childSysId);
                }

RafaRataj_0-1741169239644.png