Catalog Item: How to populate other reference fields on a form based on the logged in user?

gjz1
Giga Expert

On my catalog form I have a requirement to populate the logged in user's department and location.

I have three variables on the form - requested_by, department, location - and all three are reference fields on the catalog form and on the sys_user table (department references cmn_department, location references cmn_location).  I get the requested_by to display without a problem but I don't seem to be able to populate the requested_by's department and location from the sys_user table in the other fields.  Any idea how I can do this in a catalog item form?  I can find a lot of information for other forms but nothing specific to a catalog item. 

Thanks in advance for your help.

 

 

12 REPLIES 12

Hii,

 

You do have catalog cleint scripts available on order guide, if you dont see it by default then configure the related list on the order guide form and add it (let me know if you dont know how to do this)

 

find_real_file.png

 

Please mark my answer correct if it solves your issue.

-Anurag

-Anurag

Vishal Khandve
Kilo Sage

Hi,

try below on change client scrip-

 

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

var gr = g_form.getReference('requested_for',callBack);
}
function callBack(gr){
g_form.setValue('approvers',gr.manager);
g_form.setValue('phone_number',gr.mobile_number);
g_form.setValue('email',gr.email);
g_form.setValue('location',gr.location);
g_form.setValue('employee_number',gr.employee_number);
g_form.setValue('cost_center',gr.cost_center);
g_form.setValue('country',gr.country);
g_form.setValue('company_code',gr.company);


}

 

Thank you!

gjz1
Giga Expert

It has to be easier than creating a client script.  In my developer instance with demo data there is a record producer that has two reference variables: the first gets a group and the second gets the members of the group selected in the first variable and both use a reference qualifier.  Unfortunately I'm not able to find the code used by the reference qualifier to copy it.  Why would I need to create a client script when the OOB demo data does the same thing I want with a reference qualifier?

Demo data:

Record Producer = Grant Role Delegation Rights within a group with just two variables - group and user, both reference variables.  Selecting the group limits the users.

Group field:

find_real_file.png

User field:

find_real_file.png

this is  a business rule

 

NAme : Role Delegation Functions

https://<your instance id>.service-now.com/sys_script.do?sys_id=0149c9930a0a0b300041ce2777564999&sysparm_record_target=sys_script&sysparm_record_row=1&sysparm_record_rows=1&sysparm_record_list=nameCONTAINSDele%5EscriptCONTAINSgetRoleDelegatorGroupOptions%5EORDERBYname