- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 07:29 AM - edited 10-18-2022 07:36 AM
Hi Deepthi,
If you have got 100s of fields to hide based on selection thenyou can use below steps:
1. Create a system property of string type and save all the field's backend name into it, comma seperated. Here I am showing you how I will do it for 5 fields for an example.
Note: We are using system property here so that in future if you are to romve/add more fields, then make change in the property and not in thescript.
2. Write a Display BR and set the scratchpad object with the above system property value:
(function executeRule(current, previous /*null when async*/) {
g_scratchpad.readOnlyFields = gs.getProperty("change.readonly.fields");
})(current, previous);
3. Write an Onchange client script on the field of your choice. Here in my example I am making fields readonly based on state.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var fields = g_scratchpad.readOnlyFields;
var fieldsArr = fields.split(",");
if (g_form.getValue("state") == -1) {
fieldsArr.forEach(function(field) {
g_form.setReadOnly(field, true);
});
} else {
fieldsArr.forEach(function(field) {
g_form.setReadOnly(field, false);
});
}
}
I hope you will find this helpful. PLease let me know if this do not works or you need any clarity in any step(s).
Please mark this helpful if this helps and mark as correct if this solves your issue.
Regards,
Kamlesh