Client Script in a Catalog Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 11:28 AM
Hello guys, how are you?
I'm trying to create by myself a catalog item just for "practicing". I create a simple catalog item like "New Employee Form".
There are fields named "Position" that has three options (Manager - Analyst - Developer) and other filed named "Equipment" that has two options (Laptop - Desktop).
I would to when I select "Manager" position, just appear "Laptop" as equipment to select for ex. So, how can I do that? Can you help me? Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 11:37 AM
Hi Alexandre
Refer below article for adding dependents between 2 choices using catalog client script
Try and let us know if you're stuck.
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 03:41 AM
Hi Alexandre
There are many different way to do this.
Since just starting, let's use "Select Box" for both choices.
1. Variable definition
1.1 Position
1.2 Equipment
Method 1. Use UI Policy. If just displaying/hiding fields, UI Policy can be used.
Define UI Policy condition as "position" "is" "Manager" so the policy will execute when the position is Manager.
Then in the script, write a script to add/remove "desktop" option from equipment field.
Execute when true
function onCondition() {
g_form.removeOption('equipment', 'desktop');
}
Execute if false
function onCondition() {
g_form.addOption('equipment', 'desktop', 'Desktop');
}
Execution results
case when manager
case when not manager

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 03:48 AM
This can also be done creating Catalog Client Script. The result is the same as above.
Set Type to "onChange"
Variable name to "position"
Script
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
if (newValue == 'manager') {
g_form.removeOption('equipment', 'desktop');
} else {
g_form.addOption('equipment', 'desktop', 'Desktop');
}
}