Help with script to auto populate Manager fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2017 11:25 AM
I have a script that will populate Manager info based on the user logged in:
function onLoad() {
//Type appropriate comment here, and begin script below
var id = g_form.getValue('superv_fname');//replace 'u_first_field' with the name of your reference field.
var requester = '';
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',id);
user.query();
if ( user.next() ) {
g_form.setValue('superv_emp_id', user.employee_number);
g_form.setValue('superv_email', user.email);
g_form.setValue('superv_logid', user.user_name);
g_form.setValue('superv_title', user.title);
}
}
But I need the information update to reflect the correct values if request is for another user. I have another script I've used for this, but it will only update to reflect the 'requestor' information (email, job title, etc.), not the Manager's:
function onChange(control,
oldValue, newValue, isLoading)
{
var requester = '';
if(g_form.getValue('ConfirmInfoReqOtherChoice')
== 'No') // Which means user requesting request for himself
{
requester = g_user.userID; // This
gives login user id
}
else
{
requester =
g_form.getValue('ConfirmInfoReqName');
}
var user = new
GlideRecord('sys_user');
- user.addQuery('sys_id',requester);
- user.query();
if ( user.next() )
{
g_form.setValue('manager', user.manager);
}
}
Is there a way to combine these to get what I need?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2017 09:26 AM
Hey Nicole
There is no need for a OnLoad client script. You can put the following in on the default value of the field: javascript:gs.getUser().getManagerID()
Let me know if it worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 01:34 AM
Thank you! I was struggling for quite sometime and this worked!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 01:47 AM
Hi nicolemccray,
Set default value as: javascript:gs.getUser().getManagerName()
Please refer below screenshot.
Please mark helpful/correct based on impact.
Thanks & Regards
Darshani Sambare