querying a gliderecord within a gliderecord

davilu
Mega Sage

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!

10 REPLIES 10

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.


pradeepksharma Any inputs?


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');


}


}


miguelhidrogo
Tera Contributor

David, seems like you're missing the new statement.


Try changing
var my_manager = GlideRecord('sn_hr_core_profile');
to


var my_manager = new GlideRecord('sn_hr_core_profile');


This was my problem.  Thanks!!!