how to hide all below fields based on slection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2022 06:54 AM
hi team, i have an yes/no field, when i "no" all other below fields have to hide on form. there are almost 100 fileds where i cannot write ui policy or client script for this. i have seen there is an other simple option for this instead of ui policy. please suggest
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2022 06:57 AM
Hi
You can move all those fields into a Section and write a client script to hide the Section.
Thanks
Madhav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2022 07:08 AM - edited ‎10-18-2022 07:10 AM
but section name will appear on the form i think they will not accept it and now adding to section 100 fields is little difficult any idea
actually it is variables on catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2022 08:00 AM
Hi Deepthi,
If it is a variables on Catalog item, you can create a variable set and move all those fields into it, then you can show or hide this new Variable set using UI Policy.
Thanks
Madhava
- 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