Use reference field value not sys_id in query

sigmachiuta
Kilo Guru

Not sure why I always have trouble with reference fields.   I have a UI action that i nee to run a query on another table and see if a record exists if so proceed and if not cancel the UI action.

Do I need to query the table the reference is on and return the value and then use that in the query below?

var gr = new GlideRecord('incident');

gr.addQuery('u_foo','1234');

gr.addQuery('u_bar', 'whatever') // this is a reference field and i have to enter the sys ID here and not the display value for the query to run.

gr.query();

if(gr.next()){

gs.print(Yes!)

}

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

You can either use sys_id or dot walk to the display value on the table like this





var gr = new GlideRecord('incident');  


gr.addQuery('u_foo','1234');  


gr.addQuery('u_bar', 'sys_id goes here');


or


gr.addQuery('u_bar.name', 'Display value on the record goes here'); //assuming name is the display value on the reference table.


gr.query();  


if(gr.next()){  


 


 


gs.print(Yes!)  


 


 


}  


View solution in original post

3 REPLIES 3

Abhinay Erra
Giga Sage

You can either use sys_id or dot walk to the display value on the table like this





var gr = new GlideRecord('incident');  


gr.addQuery('u_foo','1234');  


gr.addQuery('u_bar', 'sys_id goes here');


or


gr.addQuery('u_bar.name', 'Display value on the record goes here'); //assuming name is the display value on the reference table.


gr.query();  


if(gr.next()){  


 


 


gs.print(Yes!)  


 


 


}  


I like dot walking to the display value seems a lot cleaner .   thanks that worked!


Glad you got your question answered.