Record Producer: Default value for current user's Manager

John Heuer1
Kilo Guru

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?

1 ACCEPTED SOLUTION

John Heuer1
Kilo Guru

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!

 

View solution in original post

3 REPLIES 3

Nitin_NOW
Tera Guru

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

Thank you for your reply... not quite what I needed.

John Heuer1
Kilo Guru

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!