Variable Sets vs Variables and Catalog Client Scripts

kemmy1
Tera Guru

I have a simple onChange Catalog Client Script (the applies to field is "Variable Set").  This is setting the phone number

Variable set: xxxx
Variable Name: requested_for

var caller = g_form.getReference('requested_for', setupUsersPhones);
function setupUsersPhones(caller) {
if (caller){
g_form.setValue('contact_number', caller.phone);
} }

requested_for and contact_number are both variables in the variable set.  THIS CATALOG CLIENT SCRIPT WORKS FINE.

Then I have another simple onChange Catalog Client Script (the applies to field is "Catalog Item").  This is setting the company.  Company is not part of the variable set.

Catalog Item: xxxxxx
Variable name: xxxxxx -> requested_for (xxx is the variable set name)

var caller = g_form.getReference('requested_for', setCompany);

alert(caller);
function setCompany(caller) {
if (caller){
g_form.setDisplayValue('slt_company', caller.company);
}

alert(caller); comes back undefined.  And the company is not changing either. 

Do I need to do something different in my script to "dot walk" it (for lack of a better term) to the variable set?

Lisa

1 ACCEPTED SOLUTION

Using 1 server call is certainly best in terms of performance.

But, if you want to squeeze a bit more out of the script, you should return both the sys_id and the display value for company so when you use g_form.setValue(), you can pass the display value as a third parameter.

g_form.setValue('ref_company', answer.company_sys_id, answer.company_name);

Without the display value, the platform has to go back to the server to find out what the display value is in order to show it.

Are u_branch and u_division reference variables as well?  If so, should do the same with them as well.

View solution in original post

12 REPLIES 12

SanjivMeher
Kilo Patron
Kilo Patron

Do you have both requested_for and contact_number in the same variable set?

 

If not, then you need to have the client script at catalog level


Please mark this response as correct or helpful if it assisted you with your question.

Both are Catalog Client Scripts.  Requested_for and Contact_number are in the same variable set, the second script requested_for is in the variable set and company is not in the variable set.

Must be a ServiceNow bug then. Are you trying it on Service portal?


Please mark this response as correct or helpful if it assisted you with your question.

So as far as you can tell, the script looks correct right?  Not sure why the alert(caller); line in my script is bringing back undefined, but it's definitely not getting the requested_for info from my getReference call.