We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Snehal2
Kilo Guru

Hi All,

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

find_real_file.png

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:

find_real_file.png

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.

find_real_file.png

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

find_real_file.png

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

find_real_file.pngfind_real_file.png4. Add Reference Qualifier and Variable attributes as shown in the above image.

 

Hit like if this post helps you.

 

Regards,

Snehal Madakatti

Comments
Dev M
Tera Contributor

The Script works Perfect. Thank You

Heverton1
Tera Contributor

I needed something like this and for a category and subcategory field.

Category values come from Incident table category field.

Subcategory values come from sys_choice table.

 

In the subcategory field (Look up select box), did the following:

Heverton1_0-1770644381690.png


Worked well as I have the same values of category and subcategory as in the Incident table. Also the "Dependent" behaviour works well due to the ref qualifier.

Thanks for the insight @Ashley Snyder1 

 

 

Version history
Last update:
‎12-15-2019 06:24 AM
Updated by: