The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to query reference field??

priyanayak
Kilo Contributor

HI,

I have created a table, where one column is reference to sys_user. I have added 2 users data to it. I want to query that table to check if particular user is present in that table or not.

var submittedBy = gs.getUser();

var leave_balance = new GlideRecord('u_leave_balance');

Here submittedBy is a user. and i want to query my table u_leave_balance to check if that user is present in that or not. What will be my addQuery condition??Untitled.png

7 REPLIES 7

Ashish Kumar Ag
Kilo Guru

var submittedBy = 'sys_id of user'; // (( if want to check for logged in user then gs.getUser() or add any field like current.u_fieldname;))



var gr = new GlideRecord('u_leave_balance');


gr.addQuery('u_user',submittedBy);


gr.query();


if(gr.next()){ // in case you have multiple record for a user then change if to while


// Do what ever you want to


}


Vimal Priya
Giga Guru

You can also do like this,




Var usr=g_form.getRefernce('u_user');


if(!usr.nil())


{


your code here


}




Regards,


VimalPriya S


Normally it is suggested not to use getReference, it to be used, then we should use callback function.