Auto populate manager

Sam198
Mega Guru

Hi all,

I need to autopopulate manager in the manager variable on catalog form for the request for field.

I can add to the default value - javascript:gs.getUser().getManagerID(); and it autopopulates the manager, however if the request for name is changed (for example if an EA is logging on behalf of they would change the request for field name from them to other person) - then the manager field does not update to reflect that changed users manager (stays to the logged in users manager), is there any simple code to update the manager onChange, I am guessing I need catalog client script?

 

thanks.

1 ACCEPTED SOLUTION

dvp
Mega Sage
Mega Sage

If you looking for something on the client side, you can do it using getReference

function onChange(control, oldValue, newValue, isLoading) {

	if (isLoading || newValue == '') {
      return;
   }
	
	var usr = g_form.getReference('requested_for',callBack);
	
}
function callBack(usr){
		g_form.setValue('manager',usr.manager);
}

View solution in original post

7 REPLIES 7

Raghu Loganatha
Kilo Guru

You need to write an onchange catalog client script. Select the type  as "OnChange" and variable name to the "Requestors field".

Here is the script which you need. 

var user = g_form.getValue('requested_for');
var mgr = new GlideRecord("sys_user");
mgr.addQuery("sys_id",user);
mgr.query();
if(mgr.next())
{
g_form.setValue("manager",mgr.manager);
}

Please mark this answered if this response helps. Let me know if you have any questions.


Thanks,
Raghu.

no

Brian Lancaster
Tera Sage

I think you just need to a run script in the workflow at the beginning with something like this.

current.variables.[variable name] = current.request.request_for.manager;

Brian Lancaster
Tera Sage

Another thought that brought me to a question:  Is the requested_for that you are talking about a variable on your form or is it the request_for you see when checking out?