How to auto-populate Department and Manager?

Matt Nolan1
Kilo Contributor

Hi,

I am attempting to create a variable set that automatically fills in the following information for use on catalog items and record producers. (variable name in parentheses) 

User who opened the request (requesting_user)

User's department (users_department)

User's manager (users_manager)

 

The requesting user fills in because I have the default value set to javascript:gs.getUserID()

Below are the OnLoad and OnChange scripts i have written

function onLoad(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.getReference('requesting_user', setFields);
}

function setFields(user) {
g_form.setValue('users_manager', user.manager);
g_form.setValue('users_department', user.department);
}

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.getReference('requesting_user', setFields);
}

function setFields(user) {
g_form.setValue('users_manager', user.manager);
g_form.setValue('users_department', user.department);
}

 

What am I doing wrong here? 

 

Thank you in advance for your responses

1 ACCEPTED SOLUTION

Resolved the issue. Please try now 🙂

Here are the modification

1. Set client script UI type to all. This is required to trigger script in Service Portal

2. Update OnChange CS to include variable name.

3. Updated Department variable to point to department table and not sys_user.

 

I hope this helps.

 

- Pradeep Sharma

View solution in original post

9 REPLIES 9

The Test record producer is under Office Services on the SP

Thanks for the update. Could you please remove the password from your post. I am able to get to the instance.

Resolved the issue. Please try now 🙂

Here are the modification

1. Set client script UI type to all. This is required to trigger script in Service Portal

2. Update OnChange CS to include variable name.

3. Updated Department variable to point to department table and not sys_user.

 

I hope this helps.

 

- Pradeep Sharma

That worked! thank you so much!

Hi Pradeep,

I have been similiar method but different layout of the code and it works fine but always thought it looked weird.  Would this be considered a bad practice or could there be issue(s) doing it this way? 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

if (newValue != '') {
    gr = g_form.getReference('requesting_user', function(gr) {
       g_form.setValue('users_manager', gr.manager);
       g_form.setValue('users_department', gr.department);
    });
  }
}

Thanks for feedback.

-Wesley