Filter subcategory based on category choice in Service Catalog item

Chris135
Giga Contributor

Hello everyone,

I am using the OOB 'Create Incident' feature from the 'Help' section of the Service Catalog. My users use this Service Catalog item to create incidents. I wanted to add a subcategory field to help users narrow down their issue and provide our service desk with more information.

I've added the subcategory field and mapped it to subcategory field on the incident table. I made this variable a lookup select box, selected the incident table as the 'Lookup from table', and selected subcategory as the 'Lookup value field'. When users go to fill out an incident and select their category, it is not filtering their subcategory based on their category selection. Instead, it is showing all available subcategories for users to select. For example, when a user selects the category 'Phones', it should filter out the subcategories and only show 'Personal', 'Polycom', and 'Avaya Portal'. Instead, it is showing all available subcategories. What's strange is that the subcategory filter is working as intended when viewing an incident and an ITIL user decides to re-categorize an incident.

I've searched the community and found several different ways to approach this. I've tried using a reference qual and an on change client script but was unable to get anything working. Subcategory is dependent on category in the dictionary entry. All of my subcategories have dependent category values in the dictionary entry as well.

I've attached a few screenshots to help provide some context. Any and all help would be greatly appreciated. Thank you for your time!

1 ACCEPTED SOLUTION

Best practice would say that you should call a script include since the above script will not work in Service Portal.  Here is a slightly modified version of the script that will work in Service Portal but it is still not best practice.  Also I noticed that the variable they refer to in the script is u_subcategory but since your screen shot shows you have check map filed it should match the variable name on the incident form which should just be subcategory.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   //Type appropriate comment here, and begin script below
	g_form.clearOptions('subcategory');
	g_form.addOption('subcategory', '', '-- None --');
	var gr = new GlideRecord ('sys_choice');	
 	gr.addQuery('name', 'incident');
 	gr.addQuery('element', 'subcategory');
 	gr.addQuery('dependent_value', newValue);
	gr.addOrderBy('label');
	gr.query(function(gr){
		while (gr.next()){
			g_form.addOption('subcategory', gr.value, gr.label);
		}
	});
}

View solution in original post

14 REPLIES 14

Can you share how your category field is configured on the self service form?

Absolutely. Here is how I have category configured:

find_real_file.png

I just my category the same as your and it works with my script.  Are you using the service portal?  If so do you have the UI type on the client script set to All

Hey Brian,

Sorry for any confusion. I do have the UI type set to all. Here is a picture of my client script with the code you suggested:

find_real_file.png

My catalog item is still showing all possible subcategories when selecting a specific category. Thank you for your patience and all of your assistance with this!

I see the problem.  There is a drop down called variable name.  In there you have subcategory but this should be category as this is what variable you want the script to run on change of.  In this case we want the script to run when the category changes.