CRM

Show/Hide section based on option set selection in JavaScript

In this blog, we will learn about Show/Hide section based on option set selection in JavaScript.

In this article we will see how to Show/Hide section based on option set selection in JavaScript ?

For more details Click Me

Please write this code for Show/Hide section based on option set selection in JavaScript.

JavaScript source code
new_showhidesection : This is the name of option set. using “Xrm.Page.getAttribute(“new_showhidesection”).getValue()” this code get the value of option set attribute.
generalTab : This is the name of Tab.
firstSection : This is the name of first section.
secondSection : This is the name of second section.

Notes

In section.get pass section name if you want to show and hide section.
For show section set Visibile true and for hide section set Visibile false.

function ShowhideSection() {
    //retrieve here option set selected value into value 
    var value = Xrm.Page.getAttribute("new_showhidesection").getValue();
    //Check here value contain any value or null
    if (value != null) {
        //if value equal to one
        //write here tab name which contain option set field like "General Tab"
        //In Section.get pass section name if you want to show and hide
        //For show section set visibility true
        //and for hide section set visibility False
        if (value == 1) {
 
            Xrm.Page.ui.tabs.get("generalTab").sections.get("firstSection").setVisible(true);
 
        }
        else if (value == 2) {
            Xrm.Page.ui.tabs.get("generalTab").sections.get("firstSection").setVisible(false);
        }
        else if (value == 3) {
            Xrm.Page.ui.tabs.get("generalTab").sections.get("secondSection").setVisible(true);
        }
        else if (value == 4) {
            Xrm.Page.ui.tabs.get("generalTab").sections.get("secondSection").setVisible(false);
        }
        else {
        }
    }
}

Output

show-hide-section-based-on-option-set-selection-in-javascript

show-hide-section-based-on-option-set-selection-in-javascript

Leave a Reply

Your email address will not be published. Required fields are marked *