- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 01:19 PM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2018 01:04 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 01:21 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 01:23 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 01:40 PM
Must be a ServiceNow bug then. Are you trying it on Service portal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 01:49 PM
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.