Workflow - Script to update user's manager

hongsok
Tera Contributor

Dear all,

I created a Catalog Item for user to change their manager (from current to new manager). The following script that I used to update the new_manger field after the approval of the new manager and it is not working.

Could you all help me on this? 

 

var user_ref = current.variable.caller_id;
var user_man = current.variables.new_manager;

var userU = new GlideRecord ('sys_user');
userU.addQuery('sys_id',caller_id);
userU.query();
if (userU.next()){
userU.manager = user_man;
userU.update();
current.variables.manager = current.variables.new_manager;
gs.addInfoMessage("Manager has been updated to " + user_man);
}

Regards,

Hong

1 ACCEPTED SOLUTION

Hi Hong,

Glad I could help. Since my answer solved your question, please mark my answer as correct so we can close this thread.

Brent

P.S. If my suggestion helped then please mark as helpful and/or correct so other community members can benefit from this information.

View solution in original post

6 REPLIES 6

Anurag Tripathi
Mega Patron
Mega Patron

Hey,

 

Try this

 

var user_ref = current.variable.caller_id;
var user_man = current.variables.new_manager;

var userU = new GlideRecord ('sys_user');
userU.addQuery('sys_id',user_ref );
userU.query();
if (userU.next()){
userU.manager = user_man;
userU.update();

current.variables.manager = user_man ;  //not entirely sure what you want to do here.
gs.addInfoMessage("Manager has been updated to " + user_man);
}

-Anurag

Hi, no error but the record is not updated.

SaiRaviKiran Ak
Giga Guru

Your addQuery should be userU.addQuery('sys_id',user_ref);

Brent Sutton
Mega Sage

Hi Hong,

Please try the following script in your workflow to update the managers details on the sys_user record:

var user_ref = current.variable.caller_id.getValue(); //get the sys_id of the caller
var userManValue = current.variables.new_manager.getValue(); //get the sys_id of the new manager
var userManDisplayValue = current.variables.new_manager.getDisplayValue(); //get the displayValue of the new manager

var userU = new GlideRecord('sys_user');
if (userU.get(user_ref)){ //get user record using the callers sys_id
	userU.setValue("manager",userManValue,userManDisplayValue); //set the manager's value and displayValue (prevents roundtrip to server)
	userU.update(); //update record

	current.variables.manager = current.variables.new_manager;
	gs.addInfoMessage("Manager has been updated to " + userManDisplayValue);
}

Let me know if this worked for you,

Brent

P.S. If my suggestion helped then please mark as helpful and/or correct so other community members can benefit from this information.