Onload client script to make fields visible & Mandatory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 03:39 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 03:42 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 03:45 AM
Something like below
And in the UI policy action related list add the field and what you want to do with it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 03:43 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 03:46 AM
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....