How to set field(catalog variable) value on requested item using client script

sayan3
Tera Contributor

Hi All,
We have one catalog variable type (select box). available choices are yes/no
default value is empty.
we are trying for particular condition , field value should be set to "No" and read only on requested item label.
so we are using on load client script but g_form.setValue('field_name',''); is not working.
How to achieve this.
@Ankur Bawiskar 

Thanks in advance,
Sayan Ghosh

12 REPLIES 12

Brian Lancaster
Tera Sage

Can you provide your script and a little more clarification. You say you want to set it to No on particular conditions but then in your onload script you are setting it to the default value of empty. If the default value is empty you should not have to set it onload.

Edit: Also when the form is loading is this variable visible?

sayan3
Tera Contributor

I said catalog variable's default value is an empty. we are trying to set that value "No" using on load client script.
How to achieve this.
Yes variable is visible on form while form is loading

Hi,

Please use the below steps to achieve your requirement:

function onLoad() {
    //Type appropriate comment here, and begin script below
    if (g_form.getValue('FIELDNAME') == '') { // Replace your Field Name here
        g_form.setValue('variables.VapriableName', 'no'); // Replace Variable Name here and also the correct value of "no" which you can get from your Select Box Variable choice backend value
		g_form.setReadOnly('variables.VariableName',true); // Replace your Varibale Name here/
    }
}

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

sayan3
Tera Contributor

Hi,

if (g_form.getValue('FIELDNAME') == '')

or if(g_form.getValue('variables.variable_name')=='')
which one needs to select , we want to set catalog variable value on requested item