- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2024 10:30 AM
In servicenow for catalog item i have created a 2 select box varibale like 1st one is Location and its choices are "Richmond", "Tampa", "Texas", "Nashville". 2nd one select box varibale is What computer Type? and its choices are "Laptop", "Desktop", "Docking Station". And my requirement is like if I select "Richmond" in Location field the in field What computer Type i have to show "Laptop", "Desktop" options only and if selected other options in location then in What computer Type show all option.
I have write a client script for it but its not working.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2024 01:18 AM
Hello @MayurChaudhari
- Please refer to this detailed solution:
- Variables in catalog item is configured as:
Screenshot1: variable "Location"
Screenshot2: variable What computer type?
Client Script: onChange
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Clear all existing options
g_form.clearOptions('what_computer_type');
if (newValue == 'Richmond') {
// Add specific choices for Richmond
g_form.addOption('what_computer_type', 'Laptop', 'Laptop');
g_form.addOption('what_computer_type', 'Desktop', 'Desktop');
} else {
// Add all options for other locations
g_form.addOption('what_computer_type', 'Laptop', 'Laptop');
g_form.addOption('what_computer_type', 'Desktop', 'Desktop');
g_form.addOption('what_computer_type', 'Docking Station', 'Docking Station');
}
}
Client script: onLoad
function onLoad() {
//Type appropriate comment here, and begin script below
var location = g_form.getValue('location');
g_form.clearOptions('what_computer_type');
if (location == 'Richmond') {
// Add specific choices for Richmond
g_form.addOption('what_computer_type', 'Laptop', 'Laptop');
g_form.addOption('what_computer_type', 'Desktop', 'Desktop');
}
}
Result:
Note: Please adjust the variable name and value in scripts
Hope this helps!
"If you found my answer helpful, please like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2024 10:40 AM
Do not use getControl or setOption for this, rather the supported and recommended clearOptions, addOption, and removeOption
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2024 01:18 AM
Hello @MayurChaudhari
- Please refer to this detailed solution:
- Variables in catalog item is configured as:
Screenshot1: variable "Location"
Screenshot2: variable What computer type?
Client Script: onChange
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Clear all existing options
g_form.clearOptions('what_computer_type');
if (newValue == 'Richmond') {
// Add specific choices for Richmond
g_form.addOption('what_computer_type', 'Laptop', 'Laptop');
g_form.addOption('what_computer_type', 'Desktop', 'Desktop');
} else {
// Add all options for other locations
g_form.addOption('what_computer_type', 'Laptop', 'Laptop');
g_form.addOption('what_computer_type', 'Desktop', 'Desktop');
g_form.addOption('what_computer_type', 'Docking Station', 'Docking Station');
}
}
Client script: onLoad
function onLoad() {
//Type appropriate comment here, and begin script below
var location = g_form.getValue('location');
g_form.clearOptions('what_computer_type');
if (location == 'Richmond') {
// Add specific choices for Richmond
g_form.addOption('what_computer_type', 'Laptop', 'Laptop');
g_form.addOption('what_computer_type', 'Desktop', 'Desktop');
}
}
Result:
Note: Please adjust the variable name and value in scripts
Hope this helps!
"If you found my answer helpful, please like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar