- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2018 07:15 AM
I am trying to populate a form with the logged in user manager email. I can get the manager name using the manager ID but I am have a little bit of challenge getting the manager email address.
I found this article to get manager of manager. I tried to tweak it without any luck.
How can you get manager of manage of logged-in user as default value?
gs.getUser().getUserByID(gs.getUser().getManagerID()).getManagerID();
Any guidance or direction greatly appreciated.
thanks
Alex
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2018 07:18 AM
Hi Alex,
You will need to call a glide record for this, the below should work.
var manager = new GlideRecord('sys_user');
manager.get(gs.getUser().managerID);
manager.email
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2018 07:38 AM
var manager = new GlideRecord('sys_user');
manager.get(gs.getUser().managerID);
manager_email=manager.email;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2018 07:38 AM
var manager = new GlideRecord('sys_user');
manager.get(gs.getUser().managerID);
manager_email=manager.email;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2018 07:44 AM
Hi Alex,
I haven't come across the getManagerID() method before but the below script will work:
var user = new GlideRecord('sys_user'); //glide into the user table
if(user.get(gs.getUserID())){ //get the record with the same sys_id as the currently logged in user
var managerMail = user.manager.email.getValue(); //get the value of the managers email
current.field_on_your_form = managerMail; //populate your field
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2018 07:43 AM
If you're using a string field type then default value should work with the above including manager.email on the last line. You will need to add javascript: before the first bit of code to get it to function correctly but the value will be the last output from the script.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2018 12:37 PM
Hey guys, I am not getting desired results with above script.
I created a reference field on sys_user table, and put the below code in Default value on the form field named "Supervisor email address:
var user = new GlideRecord('sys_user'); //glide into the user table
if(user.get(gs.getUserID())){ //get the record with the same sys_id as the currently logged in user
var managerMail = user.manager.email.getValue(); //get the value of the managers email
current.Supervisor_email_address = manager.email; //populate your field
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 12:59 AM
You can't put code in the default value section on the dictionary entry. You'll need to use a business rule to set the value of your reference field.
It also looks like you've mixed up my code with that from chris and runfast and it also looks like the field name might be incorrect (unless this is a service catalog variable?) Last line should be:
current.u_supervisor_email_address = managerMail; //check the field name
current.variables.Supervisor_email_address = managerMail; //if service catalog variable