- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2025 05:42 PM - edited ‎01-30-2025 05:42 PM
I've been struggling to get a Catalog Client Script to fire, in which I'm wanting to evaluate three different Catalog Variables, that when evaluated as true will fire off an alert message. The Catalog Client Script has no Variable Name chosen in the form (which I recognize may be part of the problem). It would need to work on both the Platform and the Portal, which I know can introduce more issues, becase I may need two Catalog Client scripts
I'm fairly certain that my meager coding skills have done little for my success here. All my research has proved inconclusive and I'm at a dead end. Looking for a little help or perhaps the unfortunate conclusion that one cannot evaluate changes to three different Variable answers in one onChange Catalog Client Script.
The script for:
UI Type = All
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var var1 = g_form.getValue('travel_event_1_preferred_method'); // How do you plan to travel to your Event 1 destination?
console.log("Preferred travel method is " + var1);
var var2 = g_form.getValue('travel_event_1_booked_hotel_question'); // Did you book your own hotel for Event 1
console.log("Booked own hotel answer for is " + var2);
var var3 = g_form.getValue('travel_event_1_rent_car_question'); // Do you need a rental car for Event 1?
console.log("Need a car rental answer for is " + var3);
// Check the conditions for the specific answers
if (var1 == '2' && var2 == 'No' && var3 == 'Yes') { //book own flts, not booking hotel & renting a car
alert('Please work with your Travel Arranger to book your hotel/car.');
}
}
Solved! Go to Solution.
- Labels:
-
Service Catalog
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2025 10:27 PM
Hi @Paul Porter ,
You can not access 3 variables in single onchange client script.
You can do it using below 3 ways:
1. you need to create separate onchange client scripts.
2.you can use the UI policy to where make the conditions as per requirement and in script you can add alert.
3. Use the onsubmit client script where you can check the values in variable and accordingly submit the form.
If my response finds helpful, please indicate its helpfulness by selecting Accept as Solution and Helpful.
Thanks,
Vaibhav Nikam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2025 06:23 PM
@Paul Porter I don't think one onChange script will work for multiple variables. you need to have 3 different onChange scripts for each of those variables or you can do one onSubmit script and do validation in onSubmit script.
Please mark my answer correct and helpful if this works for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2025 06:45 PM
Hello @Paul Porter
Yes, you need to specify the onChange field for the Catalog Client Script to trigger when a particular variable changes.
If you want the script to trigger on the change of three different variables, you'll need three separate onChange Client Scripts, even if they evaluate the same conditions. Each script should be tied to a specific variable to ensure it fires correctly when that variable changes.
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2025 07:01 PM
you will require 3 different onChange 1 for each variable
OR
you can have 1 onSubmit and show the info message to user if your only requirement is to show the message to user during submission
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2025 10:27 PM
Hi @Paul Porter ,
You can not access 3 variables in single onchange client script.
You can do it using below 3 ways:
1. you need to create separate onchange client scripts.
2.you can use the UI policy to where make the conditions as per requirement and in script you can add alert.
3. Use the onsubmit client script where you can check the values in variable and accordingly submit the form.
If my response finds helpful, please indicate its helpfulness by selecting Accept as Solution and Helpful.
Thanks,
Vaibhav Nikam