querying a gliderecord within a gliderecord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2017 01:50 PM
Hi Experts,
We are trying to query HR Profile for a user's manager and then re-query HR Profile to get details regarding the manager and are stuck on the syntax. Below is the current code in place:
var my_profile = new GlideRecord('sn_hr_core_profile');
my_profile.addQuery('user', sys_user);
my_profile.query();
while (my_profile.next()) {
var mgr2 = my_profile.user.manager.getRefRecord();
var mgr = mgr2.getValue('sys_id');
var my_manager = GlideRecord('sn_hr_core_profile');
my_manager.addQuery('user', mgr);
my_manager.query();
while (my_manager.next()) {
data.manager = my_manager.getDisplayValue('user');
data.manager_email = my_manager.getDisplayValue('user.email');
data.manager_phone_business = my_manager.getDisplayValue('user.phone');
data.manager_phone_mobile = my_manager.getDisplayValue('user.mobile_phone');
data.manager_phone_home = my_manager.getDisplayValue('user.home_phone');
data.manager_position = my_manager.getDisplayValue('position');
data.manager_grade = my_manager.getDisplayValue('x_salary_grade');
data.manager_eri= my_manager.getDisplayValue('x_eri);
}
Service Portal does not like the highlighted blue line and we keep getting the error: Server JavaScript error Method "ScopedGlideRecord" called on incompatible object.
I don't think it likes the fact that "new" isn't in front of GlideRecord, but even when we do put new in that line, the widget shows up blank. How do we fix that line so that our widget works? The above code worked perfectly in Helsinki, but now that we're in Istanbul, we're running into this issue...
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2017 02:28 PM
HR Profile is a core table, but our widget is in its own scoped application. We have other widgets that are within this scope querying core tables and they all seem to work fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2017 02:30 PM
pradeepksharma Any inputs?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2017 08:33 PM
Hi David,
Please check if this helps.
var my_profile = new GlideRecord('sn_hr_core_profile');
my_profile.addQuery('user', gs.getUserID());
my_profile.query();
if(my_profile.next()) {
var mgr = my_profile.getValue('manager');
var my_manager = new GlideRecord('sn_hr_core_profile');
my_manager.addQuery('user', mgr);
my_manager.query();
if(my_manager.next()) {
data.manager = my_manager.getDisplayValue('user'); // Please use the getDisplayValue() if it's a reference field else use getValue().
data.manager_email = my_manager.getValue('email');
data.manager_phone_business = my_manager.getValue('phone');
data.manager_phone_mobile = my_manager.getValue('mobile_phone');
data.manager_phone_home = my_manager.getValue('home_phone');
data.manager_position = my_manager.getValue('position');
data.manager_grade = my_manager.getValue('x_salary_grade');
data.manager_eri= my_manager.getValue('x_eri');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2017 07:33 PM
David, seems like you're missing the new statement.
Try changingvar my_manager = GlideRecord('sn_hr_core_profile');
to
var my_manager = new GlideRecord('sn_hr_core_profile');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2020 10:21 AM
This was my problem. Thanks!!!