How to set value for Description based on the choice selected in other choice field for catalog item

Deepika61
Tera Contributor

Hi All,

I have requirement that  basically there is one choice field, under choice field there description field also, so for every choice we have some text input, So whenever we select above choice 1, under decsription field we need to fill that input text automatically? like that for all other choices also need to fill corresponding text in description field?

 

Please help me on this

Thanks

Deepika

1 ACCEPTED SOLUTION

Muhammad Khan
Mega Sage
Mega Sage

Try onChange() Catalog Client Script on your choice variable and set the value of text field under the choice field. Something like below in client script should work.

 

var choiceValue = g_form.getValue('<choice_variable_backend_name>');
if(choiceValue == '<some_choice_backend_value>'){
        g_form.setValue('<text_input_variable_backend_name>', 'some text');
} else if(choiceValue == '<some_choice_backend_value>'){
        g_form.setValue('<text_input_variable_backend_name>', 'some text');
}

 

You can also try with switch cases instead of if-else.

 

If you just want to set the choice value to the text field, then utilize the below script.

 

var choiceValue = g_form.getValue('<choice_variable_backend_name>');
g_form.setValue('<text_input_variable_backend_name>', choiceValue);
// To set the lable of choice value, utilize the below statement.
//g_form.setValue('<text_input_variable_backend_name>', g_form.getOption('<choice_variable_backend_name>', newValue).text);

 

 

To map the text variable value to description, use map to field in variable configuration.

View solution in original post

1 REPLY 1

Muhammad Khan
Mega Sage
Mega Sage

Try onChange() Catalog Client Script on your choice variable and set the value of text field under the choice field. Something like below in client script should work.

 

var choiceValue = g_form.getValue('<choice_variable_backend_name>');
if(choiceValue == '<some_choice_backend_value>'){
        g_form.setValue('<text_input_variable_backend_name>', 'some text');
} else if(choiceValue == '<some_choice_backend_value>'){
        g_form.setValue('<text_input_variable_backend_name>', 'some text');
}

 

You can also try with switch cases instead of if-else.

 

If you just want to set the choice value to the text field, then utilize the below script.

 

var choiceValue = g_form.getValue('<choice_variable_backend_name>');
g_form.setValue('<text_input_variable_backend_name>', choiceValue);
// To set the lable of choice value, utilize the below statement.
//g_form.setValue('<text_input_variable_backend_name>', g_form.getOption('<choice_variable_backend_name>', newValue).text);

 

 

To map the text variable value to description, use map to field in variable configuration.