Need help with Catalog client script to show the appropriate options

New user1212
Tera Contributor

Hi
I need help writing a catalog client script for my item.
The idea is that depending on the selected Resource Group, the appropriate Resource Sub Category will appear.
I created two Select box lists 1. resource_group 2. resource_sub_group but I can't write it correctly in the script because each version displays all options..

 

Select box type: Resource Group: Interims, Persistent Externals, Occasional Externals, Non-Executives
Select box type : Resource Sub Group, to display based on resource group selected : 
  • Interims
    • Interims - via Assured Partner
    • Interims - Independents
  • Persistent Externals
    • Persistent Externals - via Assured Partner
    • Persistent Externals - Independents
  • Occasional Externals
    • Occasional Externals - via Assured Partner
    • Occasional Externals - Independents
  • Non-Executives (no additional resource sub group dropdown required for this)

This is my script but no working..

Newuser1212_0-1725275978185.png

 

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@New user1212 Instead of handling this through a client script, you should instead make Resource sub category field dependent on the Resource Group field. Please refer to this documentation https://docs.servicenow.com/bundle/xanadu-platform-administration/page/administer/field-administrati... to know more about the steps to make a field dependent on another field.

 

Hope this helps.

you can't create a dependency for a catalog item, it has to be a client script

Community Alums
Not applicable

HI, @New user1212 
You can try the script below; it works properly on my instance.

 g_form.clearOptions('resource_sub_group');
    switch (newValue) {
        case 'Interims':
            g_form.addOption('resource_sub_group', 'ABC', 'Interims - via Assured Partner');
            g_form.addOption('resource_sub_group', 'XYZ', 'Interims - Independents');
            break;
        case 'Persistent Externals':
            g_form.addOption('resource_sub_group', 'AC', 'Persistent Externals - via Assured Partner');
            g_form.addOption('resource_sub_group', 'DC', 'Persistent Externals - Independents');
            break;
 
        default:
            break;
    }
 
AishwaryaNaga1_0-1725279930179.png