setValue in select box in catalog client script

Hafsa1
Mega Sage

I have 2 region field with value as "NA" for "North America.

I am using catalog client script to fix value of first region into another and second one is read-only

But it is not updating. What wrong I'm doing?

var regions = g_form.getValue("u_region").toString();

I used g_form.setValue("u_region_1", regions );

 

10 REPLIES 10

Rajesh Chopade1
Mega Sage

hi @Hafsa1 

In your script, you're checking for nature=="3",  but the variable nature is not defined in the code you shared. Ensure that nature is properly set and that it holds the expected value before the condition.

u_region_1 is read-only, g_form.setValue might not be able to update it.

 

Here's the revised script with these fixes:

var nature = g_form.getValue('nature'); // Get the 'nature' field value

if (nature == "3") {
    var regions = g_form.getValue("u_region");
    alert("Region is: " + regions);

    g_form.setValue("u_region_1", regions);  // Set the value of u_region_1 to u_region's value

    console.log("Value of u_region_1 after set: " + g_form.getValue("u_region_1")); // Debugging

    // If u_region_1 is read-only, make it editable for a moment
    g_form.setReadOnly('u_region_1', false); // Make editable
    g_form.setValue("u_region_1", regions); // Set the value
    g_form.setReadOnly('u_region_1', true); // Make it read-only again
}

I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

Rajesh