Whats the best way to create dependent variables?

saint
Tera Expert

I want to create a category and subcategory type variables for an catalog item. Where both are select boxes, based on catalogry, options of subcategories are shown. 

I want to know the best way to make this solution robust and scalable.

1 ACCEPTED SOLUTION

Bhimashankar H
Mega Sage

Hey @saint ,

 

As you want to create variables then, it is recommended that create these variables with choice list then for second also created it as choice list, then in second variable related list, you can define the dependancy based on the first variable. 
Anytime you can go and add to choice list and specify to which it is dependant.

 

For reference you can refer to the category and subcategory fields from problem form. This will show you how to create it easily. It is easy to maintain and scalable. 

 

Thanks,

Bhimashankar

 

----------------------------------------------------------------------------------------
Please mark my answer as helpful/correct if it resolves your query.
----------------------------------------------------------------------------------------

View solution in original post

4 REPLIES 4

Shraddha Kadam
Mega Sage

Hello @saint ,

 

You can use catalog client script and in the catalog client script use g_form.addOption() and

g_form.removeOption() methods.

Syntax -

g_form.addOption('variablename','value','optiondisplayvalue',indexnumber); //To add option from the choicelist
g_form.removeOption('variablename','choicelistvalue'); //To remove option from the choicelist
If my response was helpful, please mark it as correct and helpful.
Thank you.

SumanthDosapati
Mega Sage
Mega Sage

@saint 

You can write an OnChange Client script on Category field like below

g_form.clearOptions('sub_category');
if(newValue == 'category_one')
{
g_form.addOption('subcategory', 'value1'); 
g_form.addOption('subcategory', 'value2'); 
}
else if(newValue == 'category_two')
{
g_form.addOption('subcategory', 'value3'); 
g_form.addOption('subcategory', 'value4'); 
}

Check the field names and values in the script.

 

Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth 

Bhimashankar H
Mega Sage

Hey @saint ,

 

As you want to create variables then, it is recommended that create these variables with choice list then for second also created it as choice list, then in second variable related list, you can define the dependancy based on the first variable. 
Anytime you can go and add to choice list and specify to which it is dependant.

 

For reference you can refer to the category and subcategory fields from problem form. This will show you how to create it easily. It is easy to maintain and scalable. 

 

Thanks,

Bhimashankar

 

----------------------------------------------------------------------------------------
Please mark my answer as helpful/correct if it resolves your query.
----------------------------------------------------------------------------------------

Bhimashankar H
Mega Sage

Hey @saint ,

 

Please mark as helpful or accept as solution for any reply which solves your issue. It will not only help you but also for future developers. If there any suggestion or stuck anywhere, feel free to post a reply or message me.

 

You coordination will help community to grow stronger!

 

Thanks,

Bhimashankar