Onload client script to make fields visible & Mandatory

Ankita Gupte
Kilo Sage

Hello Experts,

 

Please help with onload client script. i.e if the RITM Stage is "In-stock" then make fields a,b,c,d visible & mandatory else they should not be visible/mandatory/readonly

10 REPLIES 10

Anurag Tripathi
Mega Patron
Mega Patron

Hi Ankita,

 

You should try to do this via UI Policy.

Its will be a no code solution and its recommended to use ui policy to control field behaviour

-Anurag

Something like below

AnuragTripathi_0-1720435522743.png

 

And in the UI policy action related list add the field and what you want to do with it.

-Anurag

Satishkumar B
Giga Sage
Giga Sage

Hi @Ankita Gupte 

please check this for your ask:

 

 

function onLoad() {
    var ritmStage = g_form.getValue('stage'); // Replace 'stage' with the actual field name for RITM stage

    // Define the fields to be managed
    var fieldsToManage = ['field_a', 'field_b', 'field_c', 'field_d'];

    // Check if RITM stage is "In-stock"
    if (ritmStage == 'In-stock') {
        // Loop through fields and make them visible and mandatory
        fieldsToManage.forEach(function(field) {
            g_form.setMandatory(field, true);
            g_form.setDisplay(field, true);
            g_form.setReadonly(field, false);
        });
    } else {
        // Loop through fields and make them not mandatory and hide them
        fieldsToManage.forEach(function(field) {
            g_form.setMandatory(field, false);
            g_form.setDisplay(field, false);
            g_form.setReadonly(field, true);
        });
    }
}

 

 

-----------------------------------------------------------------------------------

Please consider marking my reply as Helpful  👍and/or Accept Solution ✔️, if applicable. Thanks!



Sohail Khilji
Kilo Patron
Kilo Patron

Hi @Ankita Gupte ,

 

No need to go with Client script , you can do it with a Ui POLICY as below:

 

table: sc_Req_item

condition : stage is instock

save it.

in the realted list ui policy action create 3 actions as below.

 

1. selet the field name  'a' and enable the mandatory check box and select display as visible.

2. select the field name as 'b' and enable the mandatory check box and select display as visible.

and on...

 

if you want to do it via client script the below is the code that goes in onload() script block

 

var v_stage = g_from.getValue(stage);

if (stage == 'in stock' {

g_from.setMandatroy('a', true);

g_form.setVisible('a', true);

 

and so on...

}


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect