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

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.


ravali6
Giga Contributor

Thanks a lot..it worked.. But can you please clarify if dot wlaking is only possible if it a reference field. Here it was not possible beacuse this is child parent relationship.

Is my understanding correct.
Thanks a lot for the help..


CapaJC
ServiceNow Employee
ServiceNow Employee

I believe your understanding is correct. You can dotwalk through a reference field, since the reference grabs the actual GlideRecord for the extension table.

Since the GlideRecord gr in your example was on the base table, however, base table fields are all you get without the extra step.


yjaques
Tera Contributor

I know this post is old, but just for reference, there actually is a way to dotwalk this stuff by using the "ref_" technique, you could do:



gr.ref_cmdb_ci_computer.form_factor