Auto populate manager field from a lookup select box field

Rohit54
Mega Guru

Hi all,

I have two fields namely User and Manager on a catalog form. Both these fields are of lookup select box type. The look up table for both is sys_user table. 

I want to populate the value of manager field as soon as someone fills user field i.e The user which is selected in the user field, his/her manager name should populate on the manager field.

I have seen a lot of articles regarding reference field but there is nothing related to look select box field. Any help would be appreciated,

Thanks

1 ACCEPTED SOLUTION

Hi Rohit,

getReference() doesn't work on lookup select box.

Refer below link if you require to use Lookup select box

[SOLVED]: - Dependent variable on Catalog item using Lookup Select Box

OR

Make both the variables as reference type

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Did you try out onChange Client Script on the User variable along with GlideAjax

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur, 

I have used a onChange client script as follow:

function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
g_form.clearValue('manager');
return;
}
var req = g_form.getReference('user', fillmanager);

}

function fillmanager(req) {
g_form.setValue('manager', req.manager);
}

 

The variable name in the onChange was user.

Please see the screenshot attached for more clarity

Hi Rohit,

getReference() doesn't work on lookup select box.

Refer below link if you require to use Lookup select box

[SOLVED]: - Dependent variable on Catalog item using Lookup Select Box

OR

Make both the variables as reference type

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Rohit ,

No scripting is required for this use case. You can accomplish this via Reference qualifier

1. In the first lookup select box set the Lookup Value field to SysId and Lookup Label to which ever field you want to display

2. Now in the second lookup select box set the lookup value field to what ever field you want and Lookup Label to Manager field with reference qualifier value as javascript:'sys_id='+current.variables.PASS FIRST LOOKUP SELECTBOX VARIABLE NAME HERE; and update the variable attribute as ref_qual_elements=PASS FIRST LOOKUP SELECTBOX VARIABLE NAME HERE

 

- Pradeep Sharma