- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2019 10:11 AM
Hello,
I've seen numerous articles posted about retrieving the Manager of a currently logged in user, however, none of the examples are working for me. It appears as if the getManagerID() and getManagerName() function/methods simply aren't enabled, if that's even a possibility.
What we're trying to do is have a Record Producer with two fields:
1) Requestor Name (reference field) - Auto populates to current user. *Works perfectly*
2) Requestor's Manager (reference field) -Auto populates to the Manager of the currently logged in user
Nothing I try populates anything in the Requestor's Manager:
- javascript:gs.getUser().getManagerID();
- javascript:gs.getUser().getManagerName();
- javascript:gs.getUser().getClientData("manager");
I've even tried on the Vendor record to populate the default value from there, with no results.
I've confirmed the logged in user does have a manager (user record is active), and selecting manually does work.
It feels like I'm missing something obvious... any thoughts?
EDIT:
Worth noting, I am working in the GRC: Vendor Risk Management scope. Perhaps it's a cross scope access issue?
Solved! Go to Solution.
- Labels:
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2019 11:01 AM
Worked with a colleague and found the solution. The issue is because of the cross scope access.
1) Create a new Script Include:
var VendorHelperUtils = Class.create();
VendorHelperUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getManager: function() {
var managerSysID;
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
user.query();
while(user.next()){
managerSysID = user.manager;
}
return managerSysID;
},
type: 'VendorHelperUtils'
});
2) In the Variable on the Record Producer, add the following to Default Value to call the function in the Script Include:
javascript:new VendorHelperUtils().getManager();
Works perfectly!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2019 10:22 AM
Hello John
It doesn't populate automatically with the Default value. There should be a onLoad() and onChange() CS to be created so it starts working.
Sample CS:
function onLoad() {
var strReqestedFor = g_form.getReference('vs_requested_for',test);
}
function test(strReqestedFor)
{
g_form.setValue('vs_manager', strReqestedFor.manager);
g_form.setValue('vs_email', strReqestedFor.email);
g_form.setValue('vs_location', strReqestedFor.location);
g_form.setValue('vs_department', strReqestedFor.department);
}
Please hit correct based on impact of response.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2019 11:03 AM
Thank you for your reply... not quite what I needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2019 11:01 AM
Worked with a colleague and found the solution. The issue is because of the cross scope access.
1) Create a new Script Include:
var VendorHelperUtils = Class.create();
VendorHelperUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getManager: function() {
var managerSysID;
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
user.query();
while(user.next()){
managerSysID = user.manager;
}
return managerSysID;
},
type: 'VendorHelperUtils'
});
2) In the Variable on the Record Producer, add the following to Default Value to call the function in the Script Include:
javascript:new VendorHelperUtils().getManager();
Works perfectly!