logo

NJP

Creating Dependent Variables in Service Catalog? Here are two ways how it can be done.

Import · Dec 15, 2019 · article

Hi All,

Unfortunately, catalog variables do not have a dependency like a field we have on the forms.

image

The dependent variables can be created in the service catalog in two ways:

A. Using Client Script: Onchange of Category field write following script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '')
    {
        g_form.clearOptions('subcategory');
        g_form.addOption('subcategory', '', '-- None --');
        return;
    }
    if(newValue =='Category 1')
        {
        g_form.clearOptions('subcategory');
        g_form.addOption('subcategory', '', '-- None --');
        g_form.addOption('subcategory','Subcategory11','Subcategory11');
        g_form.addOption('subcategory','Subcategory12','Subcategory12');
        g_form.addOption('subcategory','Subcategory13','Subcategory13');
    }
    else if(newValue =='Category 2')
    {
        g_form.clearOptions('subcategory');
        //g_form.addOption('subcategory', '', '-- None --');
        g_form.addOption('subcategory','Subcategory21','Subcategory21');
        g_form.addOption('subcategory','Subcategory22','Subcategory22');
        g_form.addOption('subcategory','Subcategory23','Subcategory23');
    }
    else if(newValue =='Category 3')
    {
        g_form.clearOptions('subcategory');
        g_form.addOption('subcategory', '', '-- None --');
        g_form.addOption('subcategory','Subcategory31','Subcategory31');
        g_form.addOption('subcategory','Subcategory32','Subcategory32');
        g_form.addOption('subcategory','Subcategory33','Subcategory33');
    }   
}

B. By Creating the table:

The client script cannot be used when we have a large number of categories and subcategories. So in such a case, we have to follow the 2nd way i.e create a table. Following are the steps you need to follow:

image

Now consider bank name as category and Bank choice as subcategory.

STEPS:

1. Create a custom table that contains the values of the category and subcategory. This will act as a dependency table.

image

2. Create Category - type of variable->Select box , and add all the required choices

image

3. Create Subcategory - type of variable->Lookup select box

imageimage4. Add Reference Qualifier and Variable attributes as shown in the above image.

Hit like if this post helps you.

Regards,

Snehal Madakatti

View original source

https://www.servicenow.com/community/developer-articles/creating-dependent-variables-in-service-catalog-here-are-two/ta-p/2298531