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 01:53 PM
This really shouldn't be an issue. But given that you are likely to search for only one record in both next() queries, have you considered switching over to .get(sys_id) instead?
Also, move all object declarations outside of any if/for/while structures. It should always be at the beginning of your code unless it is absolutely necessary.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2017 02:12 PM
I think this is because of the cross scope issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2017 02:18 PM
Hi Srini,
What do you mean by cross scope issue? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2017 02:22 PM
I means, Are they both from different application scopes?
Below link can help you providing more info.
Business rules in scoped applications