Selectct Box – Autopopulate field when only 1 option is available

Elton2
Tera Contributor

Hi everyone, how are you?!
I created a catalog item and some variables and checked “NONE” (img1), but when there is only 1 option, I would like the option to be Auto Populated with the only available value (img2).
I created a Client Script, but it is not working (img3):

 

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

    var custReq = g_form.getElement('subservice');

    if (custReq.options.length == 1) {

        g_form.setValue('subservice', custReq.options[0].value);

    }
 
}
 
 
Note: I also found this same question here in the community, so I tried to use it by changing the field to “subservice” (which is the field I need – img4), but it didn’t work:
 
Obs.: “None” option only makes sense when there is more than one option, but when there is only 1 option, I would like the auto-populated field to appear with the only available value.
 
Could someone help me?
Thanks 😉
 
2 REPLIES 2

maroon_byte
Mega Sage

Your catalog client script is doing DOM manipulation. So try with 'Isolate Script' checked (or setting it to true from list view).

 

Regards,

Sharad

Hi @maroon_byte, how are you?!

 

I accessed the "catalog_script_client" table and checked "true" (isolate script and Active - img), but that didn't work. ;(

 

Do you have another suggestion?! 

Thanks again