- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2018 09:08 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2018 10:54 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2018 09:16 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2018 10:03 AM
Hi, no error but the record is not updated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2018 09:19 AM
Your addQuery should be userU.addQuery('sys_id',user_ref);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2018 03:09 PM
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.