How to make dependency value from the choice table on Catalog ITEM.

B Ashok
Tera Guru

Hi Team, 

 

I have created two Elements : ElementA and ElementB with choice list. 

 

BAshok_0-1701260815371.png

 

BAshok_1-1701260845197.png

Note : Field names : u_element_a  , u_element_b

I need to populate only B1, B2 when selected A1, and Populated B2,B3 when selected A2 like wise. 

Created below Catalog Client Script can't fix this issue. Can some one please help with script. 

 

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

   
    function onChangeElementA() {
      
        var elementAValue = g_form.getValue('u_element_a');

        
        setChoicesForElementB(elementAValue);
    }

    function setChoicesForElementB(elementAValue) {
        
        var choicesForElementB = getChoicesForElementB(elementAValue);
 
        g_form.clearOptions('u_element_b'); 
        g_form.addOptions('u_element_b', choicesForElementB);
    }

    function getChoicesForElementB(elementAValue) {
        
       
        var choices = [];
        if (elementAValue == 'A1') {
            choices = ['B1', 'B2'];
        } else if (elementAValue == 'A2') {
            choices = ['B2', 'B3'];
        } else if (elementAValue == 'A3') {
            choices = ['B3', 'B1'];
        }

        return choices;
    }
 
    g_form.observe('u_element_b', onChangeElementA);

}
----------------------------------------------------------------------------------