The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
SlightlyLoony
Tera Contributor

find_real_file.pngSometimes when you're writing a script, you need to query one table but get results based on fields in another, related table. For example, you might want to query for NICs on Windows servers. The NIC table itself doesn't know what kind of CI it's related to — that information is in the related CI. You can do this with filters, but how do you do it in script?

Here's how (using the example above):


var gr = new GlideRecord('cmdb_ci_network_adapter');
gr.addQuery('cmdb_ci.sys_class_name', 'cmdb_ci_windows_server');
gr.query();

Presto! At the end of that simple little script, you've got a list of all the NICs on Windows servers.

The trick lies in the first argument to the addQuery() method. Notice the dot? That tells you that the query is going to be "dot-walking". In this case, the cmdb_ci field in the cmdb_ci_network_adapter table is a reference field, referring to the CI that a NIC is related to. The sys_class_name field of the cmdb_ci table specifies what kind of CI it is, and cmdb_ci_windows_server is the kind we're looking for.

Easy, wasn't it?

2 Comments