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-14-2017 04:11 PM
Hi Nicole,
I don't see where you've used the 'requester' variable in your scripts.Also, do you want the fields to auto populate based on the user or the value in the superv_fname field, because I see you've queried the user table with supervisor's id rather than the users.
I wouldn't suggest a GlideRecord on client scripts. You could use, call back functions in the client script.
function onLoad() {
//Type appropriate comment here, and begin script below
g_form.getReference("superv_fname", function(gr){
g_form.setValue("superv_email'", gr.email);
g_form.setValue("superv_phone", gr.phone);
//add the other fields you want here.
});
}
You could use the same script for onChange as well. So, whenever the superv_fname changes, the phone and other fields are populated.
Darshak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2017 05:42 AM
This worked great to populate the Supervisor fields, but I used the same script for 'onChange' to update if Supervisor changed, and it is not working. I think I'm missing the part of the script to update the Supervisor first (superv_fname) based on the user indicated in 'ConfirmInfoReqName', and then update the other fields based on that:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2017 05:44 AM
why don't you use glide ajax instead of call back function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2017 09:21 AM
Hey Nicole,
Can you try this,
function onChange(control, oldValue, newValue, isLoading) {
g_form.getReference("superv_fname", function(gr){
g_form.setValue("superv_email'", gr.email);
g_form.setValue("superv_phone", gr.phone);
//add the other fields you want here.
});
}
Darshak