Where shall we use "instanceOf" operator in Service Now?

Shantharao
Kilo Sage

Hi All,

Could any one give the real time example of "instanceOf" operator in service now, How can we use this operator and where can we use this operator

Thank you

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Hi /burra,



you can typically use it anywhere on server side to create objects, e.g.



gr instanceof GlideRecord


-Anurag

Alikutty A
Tera Sage

You can use it for shortening or simplifying complex class filters in your reference qualifier



For example, you can use the INSTANCEOF operator for a reference field to the cmdb_ci table to specify that you want all subclasses of a class included in the results. The following reference qualifier returns all servers, including Linux, UNIX, Windows, and so on, because each of those subclasses extend the cmdb_ci_server class:



sys_class_nameINSTANCEOFcmdb_ci_server alone in reference qualifier will satisfy your requirement



Use the INSTANCEOF operator





Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


Nirisha5
Tera Contributor

How can we use embed other variable value in the sys_class_nameINSTANCEOFcmdb_ci_server when iam trying to use like this it is not working 'sys_class_nameINSTANCEOF'+current.variables.ci_class

in GlideRecord you do not have the INSTANCE OF 

RafaRataj_1-1741169269741.png

but 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