Notifications
Announcements
Hi all
how to Hide and show Section Based On OptionSet
In My Tab I have 3 Section Based On OptionSet Value i Need to Show and Hide Section Please Give Some Suggestions ???
*This post is locked for comments
HI KNK,
You can do that
in the following way by calling this function onload of Form and onChange of Optionset field
function ShowHideSectionsBySubject() {
var tabName = "tab_Name";
var sectionPicklistValue = Xrm.Page.data.entity.attributes.get("optionset_field").getValue();
if(sectionPicklistValue == 1)
{
Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex1).setVisible(false);
Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex2).setVisible(true);
Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex3).setVisible(true);
}
else if(sectionPicklistValue == 2)
Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex2).setVisible(false);
Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex1).setVisible(true);
else if(sectionPicklistValue == 3)
Xrm.Page.ui.tabs.get(tabIndex).sections.get(sectionIndex3).setVisible(false);
Hi there,
I'm trying to something very similar. I have two sections on a form, both in the same Tab. I want them to hid based off the value of an option set field. I added this script onChange of the field I want it base it off, but doesn't work.
Thank You
Leibish Ringel
Hi,
There are two ways to hide sections based on option set value.
1. Using Business Rules: Hiding all the fields contained in a section automatically hides the section. This can be used especially when you have few fields in your section.
2. Using Javascript: You can also show/hide a section using this JS code:
Xrm.Page.ui.tabs.get("tabname").sections.get("sectioname").setVisible(true); //Shows a section Xrm.Page.ui.tabs.get("tabname").sections.get("sectioname").setVisible(false); //Hides a section
Register the below function on-load event of the form as well as the on-change event of the option set field and hide and show sections as required.
function HideOrShowSectionBasedOnoptionSetValue(){ var value = Xrm.Page.getAttribute("optionSetFieldName").getValue(); if(value!=null){ if(value == 1){ Xrm.Page.ui.tabs.get("tabname").sections.get("section1Name").setVisible(true); //Shows section 1 Xrm.Page.ui.tabs.get("tabname").sections.get("section2Name").setVisible(false); //Hides section 2 Xrm.Page.ui.tabs.get("tabname").sections.get("section3Name").setVisible(false); //Hides section 3 } else if(value == 2){ Xrm.Page.ui.tabs.get("tabname").sections.get("section1Name").setVisible(false); //Hides section 1 Xrm.Page.ui.tabs.get("tabname").sections.get("section2Name").setVisible(true); //Shows section 2 Xrm.Page.ui.tabs.get("tabname").sections.get("section3Name").setVisible(false); //Hides section 3 } else if(value ==3){ Xrm.Page.ui.tabs.get("tabname").sections.get("section1Name").setVisible(false); //Hides section 1 Xrm.Page.ui.tabs.get("tabname").sections.get("section2Name").setVisible(false); //Hides section 2 Xrm.Page.ui.tabs.get("tabname").sections.get("section3Name").setVisible(true); //Showssection 3 } } }
Hope this helps.
Hi Nithya,
Thank you for your reply.
When I register the function do I add anything to the parameter list?
Not needed. What Nithya replied is pitch perfect and needs no more edits.
Regards,
Sravan.
Hi Sravan,
I copied the exact script and added my corresponding fields, tab and sections name to the script
function HideOrShowSectionBasedOnoptionSetValue(){
var value = Xrm.Page.getAttribute("msdyn_ordertype").getValue();
if(value!=null){
if(value == 1){
Xrm.Page.ui.tabs.get("Summary").sections.get("Insurance_Information").setVisible(true);
Xrm.Page.ui.tabs.get("Summary").sections.get("Secondary_Insurance").setVisible(true);
else if(value == 2){
Xrm.Page.ui.tabs.get("Summary").sections.get("Insurance_Information").setVisible(false);
Xrm.Page.ui.tabs.get("Summary").sections.get("Secondary_Insurance").setVisible(false);
and go this error,
Script Error
One of the scripts for this record has caused an error. For more details, download the log file.
TypeError: Cannot read property 'setVisible' of null at HideOrShowSectionBasedOnoptionSetValue
Is there something I still need to do or am I doing this wrong?
Hi Lebish,
Please ensure that the names of sections and tabs are the same as they appear in the Tab and Section Properties.
In order to get these names, Select the Tab or Section in the Form Editor and click on Change Properties in the command bar.
The names of tab and section are highlighted in the screenshots below.
aspsolutionkirit.blogspot.in/.../hideshow-field-based-on-option-set-in.html
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Shidin Haridas 2
Abdullah13 1