Catalog Client Script: When one variable is selected then set value in another variable on the catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 06:48 AM
Good Morning All,
I have a catalog item with a variable called department_name.
When you select "Bankruptcy" as the department then my client script will set a few checkbox variables on the form to true. This script is simple and works perfectly from the Service Catalog UI but not from the Portal UI. I have set the UI Type=All on the Catalog Client Script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue == '3a95af9fdbb8df009dc573d78c96194f') //If department_name is Bankruptcy
g_form.setValue('variables.lc_app_7zip', 'false');
g_form.setValue('variables.lc_app_AACER', 'true');
g_form.setValue('variables.lc_app_ACCURING', 'false');
}
Just for reference:
When you pick a department, I have a client script that will fire for each department then 'check' each application variable on the same screen that the department needs access to. This works when using the ServiceCatalog UI but not the Portal.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 07:00 AM
Hi,
Please check the catalog client script UI type has been set to Both.
-Dharani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 07:03 AM
Hi,
Any error you are getting in browser console when the script runs in portal?
Can you check that.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 07:53 AM
I think I found the answer.
I read this text in one of the docs.
Note: Using the variables.var_name
notation with the g_form API is not supported in Service Portal. g_form as a global object cannot be used in a widget client controller or in a UI script.
I thought I had tried my script without the leading text "variables", but I tried again and now the script works.
Instead of...
g_form.setValue('variables.lc_app_7zip', 'true');
which works on the catalog UI but not portal
I used...
g_form.setValue('lc_app_7zip', 'true');
this also works on the catalog UI AND on the portal.