GlideRecord and Reference Fields

kemmy1
Tera Guru

Is there anyway I can do an addQuery on the display value of a reference field?

u_iccb_fisma_id is a reference field to the cmdb_ci_service table.   I know the u_iccb_fisma_id is actually the sys_id.  

Or do I have to do a GlideRecord on the cmdb_ci_service table first to get the sys_id first and THEN do a GlideRecord on the u_iccb_fisma_information table to add to the query.   (there's going to be multiple u_iccb_fisma_id's that I will be querying on, so it will eventually be addQuery('u_iccb_fisma_id', 'IN', 'ABC, XYZ....');

 

var gr = new GlideRecord('u_iccb_fisma_information');

gr.addQuery('u_iccb_change_request_number', 'b528a518dbbbc3003a8034cc7c9619d7');

gr.addQuery('u_iccb_fisma_id', 'ABC');

gr.query();

      if(gr.next()){

          test = true;

          }    

Thanks!

Lisa

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Lisa,



You can do it via dot-walking i.e Replace gr.addQuery('u_iccb_fisma_id', 'ABC'); with gr.addQuery('u_iccb_fisma_id.name', 'ABC'); //Here name refers to field in cmdb_ci_service table.


View solution in original post

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Lisa,



You can do it via dot-walking i.e Replace gr.addQuery('u_iccb_fisma_id', 'ABC'); with gr.addQuery('u_iccb_fisma_id.name', 'ABC'); //Here name refers to field in cmdb_ci_service table.


#Pradeeped


Now why didn't I think of that!!??!!     Thanks everyone for the answer.  


Uncle Rob
Kilo Patron

Dot walk up to the display field for the table that field references:   Don't know what that might be for your custom table, so I'll illustrate with Incident:



var rotisserie_chicken = new GlideRecord('incident');


rotisserie_chicken.addQuery('caller_id.user_name','Prostetnic Vogon Jeltz');


rotisserie_chicken.query();