How to make Variables in Catalog item Dependent?

micky09
Tera Contributor

I have two variables 'Model' with more than 50 choice list values, and another values as 'Spare Part' with more than 200 choice list values need to make Spare Part field  dependent on the value selected in Model Field.

I know a way of doing this by client script using Add option, clear option, but as there are numerous values are there so is there any other way by which i can achieve this?

10 REPLIES 10

Akash4
Kilo Sage
Kilo Sage

Hi Micky,

One other way is to create a new table and assign the Category to Subcategory. After which you can use the basic configurations to link up both using lookup select-box.

Here is how - Dependent variable on Catalog item using Lookup Select Box

Regards, Akash

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

Harshal Gawali
Giga Guru

Hello Micky,

@Akash Kodiganti mentioned is correct. You need to create table and create record for category and subcategory into that table. Create a custom table that contains the values of the category and subcategory. This will act as a dependency table.

For more details, Please check below article.

Creating Dependent Variables in Service Catalog

 

Regards,

Harshal.

ryan_pope
Mega Guru

Rather than creating custom tables (because custom tables now can have an impact on licensing cost, unless you utilize , I might suggest you look into using the Model and Model category tables to control the model names, and distinguish between "Spare parts" and "Models". Then, to make them dependent, you can use something like this:

There are a couple of moving parts in order to get dependent variables on a catalog item. This approach will walk through how to do so where the second variable is a select box, lookup select box or reference variable.
 
Variables Requirements:
There is a dependency on their being some mechanism for the first variable value being reference-able in relation to the second.
    Ex1: Variable 1: Location reference variable, Variable 2: Building reference variable, where building records have a reference to the Location table.
    Ex2: Variable 1: Select box of categories, Variable 2: Lookup select box of subcategories. (My approach for these is, rather than add them a select box using the question_choice table, I add them directly to the sys_choice table, which has a field OOB for "Dependent Value". The "Lookup value field" should be "Sys ID", and the "Lookup label field(s)" should be "label". For each subcategory, the dependent value should be the *value* (not label) of the corresponding category).
                
 
Dynamic Filtering Setup:
  1. Write a script include function that takes a parameter (which will be the first variable's value) to query the reference table of the second variable, and return a stringified encoded query based on that query.
Ex:
var VarDependencyUtils = Class.create();
VarDependencyUtils.prototype = {
    initialize: function() {
    },
    catSubCatFilter: function(categoryValue) {
        
        var choices = new GlideRecord('sys_choice');
        choices.addQuery('name', 'question_choice');
        choices.addQuery('element', 'subcategory');
        choices.addQuery('dependent_value', categoryValue);
        choices.query();
        
        var choicesArr = [];
        while (choices.next()){
            choicesArr.push(choices.sys_id + '');
        }
        
        var returnQuery = 'sys_idIN' + choicesArr.join();
        return returnQuery;
        
    },
    type: 'VarDependencyUtils'
};
 
  1. We need to tell the system that the first variable has a dependency on it. To do this, in the "Default Value" tab (at least this is usually where it is), we need to add the following to the "Variable attributes" field:
ref_qual_elements=subcategory
 
  1. For the second variable, we also need to tell the system that this variable is dependent on the first. Following the same navigation as the previous step, add the following to the "Variable attributes" field:
ref_qual_elements=category
 
  1. Finally, in the "Type Specifications" tab (again, this is usually where this field is), we need to add the following to the "Reference qual" field:
javascript:new VarDependencyUtils().catSubCatFilter(current.variables.category);
 
Voila! You now have a variable that is dependent on another!