Onchange client script - select box variable

J_31
Kilo Sage

J_31_0-1701230035454.png

I want to create a onchange catalog client script for State/Market variable.

 

if the value of state/market is choosen as "texas" and value of Do you need to set it up as is  "standard_tx"

 

I need to add option to care manager type/skills variable. 

 

I created a onchange client script for variable - state/market , but its not working:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if ((newValue == 'texas') && (g_form.getValue("do_you_need_to_be_set_up_as") == "standard_tx")) {
       
        g_form.addOption('care_mgr_type', 'bx', "bexardemo");

    }
    //Type appropriate comment here, and begin script below

}

 

10 REPLIES 10

Shruti
Mega Sage
Mega Sage

Hi,

Create a Catalog UI policy

Apply the condition 

if the value of state/market is choosen as "texas" and value of Do you need to set it up as is  "standard_tx"

and in the run scripts section try below code

Shruti_0-1701231518017.png

 

AshishKM
Kilo Patron
Kilo Patron

Hi @J_31 , 

As you already written the catalog client script, what's the issue with that. 

 

add the alert() for newValue [ before if and inside If ] and check the selected value. 

you can try with g_form.getValue(<state/market>); // replate the correct variable and add the alert for that.

 

Share the result, if its not working.

 

-Thanks,

AshishKMishra


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Danish Bhairag2
Tera Sage

Hi @J_31 ,

 

Ur script will not give u the desired result because it is running on change of the state/market variable & by that time for other variable "do u need to be setup as" is still empty so ur condition will never evaluate to true.

 

So the best option would be to create a UI policy as Shruti mentioned  Or if u want to use onChange script then u need to create it on both the variables which is state/marketdo u need to be setup as.

 

Thanks,

Danish

 

@Danish Bhairag2 Good catch, i didn't notice the onChange variable. 

@J_31 , you have root cause , why this script is not working , you just need to replate the onChange variables 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
   var stateMarket = g_form.getValue("VariableName"); // replace the correct variable
   
   if( (stateMarket =='texas' ) && (g_form.getValue("do_you_need_to_be_set_up_as") == "standard_tx")){
        g_form.addOption('care_mgr_type', 'bx', "bexardemo");
    }
}

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution