Access extended table fields

ravali6
Giga Contributor

Hi,

I have a table cmdb_ci_computer which extends cmdb_ci table. In one of the email notifications, I am tryign to get the fields from cmdb_ci and 2 feilds from cmdb_Ci_compter( which is a child of cmdb_ci)

var gr = new GlideRecord("cmdb_ci");
gr.addQuery('assigned_to', current.requested_for);
gr.query();
while(gr.next()) {

if(gr.sys_class_name == 'cmdb_ci_computer')
{
template.print("Employee has "+gr.sys_class_name.getDisplayValue()+ "\n");
template.print("Form factor "+gr.cmdb_ci_computer.form_factor+ "\n"); // this is computer_ci_computer table
template.print("Asset Tag "+gr.asset_tag+ "\n"); //This cmdb_ci field//
template.print("------------------------\n");
}
}


I am trying to access form factor from amdb_ci_computer. I know I can do one more glide query, but can I do with dot walking to child table?

Thanks

1 ACCEPTED SOLUTION

CapaJC
ServiceNow Employee
ServiceNow Employee

You can't just dotwalk, unfortunately. But if you have a GlideRecord gr for the base table (cmdb_ci), you can do the following to get a GlideRecord for the extension table, where you'll have access to the extension table's fields:



var gr2 = new GlideRecordUtil().getGR(gr.sys_class_name, gr.sys_id);

GlideRecordUtil is a Script Include.


View solution in original post

5 REPLIES 5

Thanks a lot! This even works for REST requests!