How to query reference field??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2015 11:47 PM
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??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2015 12:20 AM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2015 02:47 AM
You can also do like this,
Var usr=g_form.getRefernce('u_user');
if(!usr.nil())
{
your code here
}
Regards,
VimalPriya S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2015 03:26 AM
Normally it is suggested not to use getReference, it to be used, then we should use callback function.