web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Not able to hide the Form Sections in d365 using JS.

(1) ShareShare
ReportReport
Posted on by 421
Hi All,
 
I have a simple requirement to show hide the section, as i have a requirement to change the fields order on the form based on a two option field (Yes/No).
 
I have a field "Platform Based", when it will be Yes, then on the opportunity form Account will be above and contact would be below the account and when the "Platform Base" become No, then it will show reverse, to achieve this, I have created two section with the same fields only with the position change of Account and contact.
This is working fine, I have one more optionset field, where only two options are visible and on that field i am showing and hiding the header fields, as soon as I am updating this optionset field then the header show hide logic is working properly but my both sections are getting visible automatically even I am not triggering my section show hide logic on that condition. By default both sections are hidden.
 
Below is my code
function hideShowGeneralTabAndFields(executionContext) {
    var formContext = executionContext.getFormContext();
    var platFormBased = formContext.getAttribute("platformbased").getValue();
    var optionset = formContext.getAttribute("optionset").getValue();
    if(platFormBased == true)
    {      
       
        if (optionset == 11 && platFormBased == true) {   //BDC
            formContext.getControl("header_field1").setVisible(false);
            formContext.getControl("header_field2").setVisible(true);      
            formContext.ui.tabs.get("General").sections.get("tab_10_section_1").setVisible(false);
            formContext.ui.tabs.get("General").sections.get("General_section_2").setVisible(true);
           
           
        }else if(optionset == 12 && platFormBased == true){ // FUND  
            formContext.getControl("header_field1").setVisible(true);
            formContext.getControl("header_field2").setVisible(false);  
            formContext.ui.tabs.get("General").sections.get("tab_10_section_1").setVisible(false);
            formContext.ui.tabs.get("General").sections.get("General_section_2").setVisible(true);
           
        }
    }else{
       
       
        formContext.ui.tabs.get("General").sections.get("tab_10_section_1").setVisible(true);
        formContext.ui.tabs.get("General").sections.get("General_section_2").setVisible(false);
    }
}
 
Categories:
I have the same question (0)
  • Himanshu Kamboj Profile Picture
    421 on at
    Not able to hide the Form Sections in d365 using JS.
    I got the Issue,
     
    There is one another Option-set field with 4-5 options(Global Option-set), as I am removing that field then all things working fine, as soon as I am adding that option-set field on the form then it is start behaving like, it is start showing both the sections on the form .
    And I have disabled all functions reg to that field, that field is not being used anywhere in the script.
  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at
    Not able to hide the Form Sections in d365 using JS.
    Hi Himanshu,
     
    Please provide a structure of all the sections as well as fields that you have added to it.
     
    Thank you,
    Amit Katariya
     
     
  • Himanshu Kamboj Profile Picture
    421 on at
    Not able to hide the Form Sections in d365 using JS.
    Hi Mahendar!
     
    I have debugged my code and found that it is going according to the logic and even it is not showing and hiding on through the code(using: formContext.ui.tabs.get("General").sections.get("tab_10_section_1").setVisible(false); )  but after completion of execution, when I am releasing the debugger at that time it is shoing both the tabs.
     
    Even I have observed one more scenario that, it is not hiding the tab when I am unchecking the "Visible By default" oob check box. I have created one more dummy tab and removed the previously created new tab reference from the code and make that previously created tab hidden by default but it is not hidden, it is still showing.
  • Himanshu Kamboj Profile Picture
    421 on at
    Not able to hide the Form Sections in d365 using JS.
    Hi Neeraj,
     
    Thanks for the solution!
     
    I have checked each and every point Neerja, before posting here my code was isolated only.
    Show hide logic for section was separate function and show hide header fields were in the separate section, this logic is working fine on change of "Platform based"(yes/no boolean field) but it is not working for Structure(Optionset with only two options ) field.
    for now I have separated both the logic but still happening the same.
    It is not working when I am changing the Structure Option-set field (FUND,BDC), on change of Platform based it is working fine.
     
     
    function hideShowGeneralTab(executionContext) {
        var formContext = executionContext.getFormContext();
        var platFormBased = formContext.getAttribute("platformbased").getValue();
        var structure = formContext.getAttribute("optionset").getValue();
        parent.Xrm.Page.ui.tabs.get("General").sections.get("section1").setVisible(false);
        parent.Xrm.Page.ui.tabs.get("General").sections.get("section2").setVisible(false);
        if(platFormBased == true)
        {
           
            if (structure == 11 && platFormBased == true) {   //BDC
                parent.Xrm.Page.ui.tabs.get("General").sections.get("section1").setVisible(false);
                parent.Xrm.Page.ui.tabs.get("General").sections.get("section2").setVisible(true);
            }else if(structure == 12 && platFormBased == true){ // FUND  
                parent.Xrm.Page.ui.tabs.get("General").sections.get("section1").setVisible(false);
                parent.Xrm.Page.ui.tabs.get("General").sections.get("section2").setVisible(true);
            }
        }else{
            parent.Xrm.Page.ui.tabs.get("General").sections.get("section1").setVisible(true);
            parent.Xrm.Page.ui.tabs.get("General").sections.get("section2").setVisible(false);
        }
    }
  • Mahendar Pal Profile Picture
    45,095 on at
    Not able to hide the Form Sections in d365 using JS.
    Hi Himanshu,
     
    Did you try to debug your code if not try that, you will see how control is moving to different sections :)
     
  • Suggested answer
    Neeraj Agrawal Profile Picture
    13 on at
    Not able to hide the Form Sections in d365 using JS.
    Hello Himanshu ,
     
    This can be due to a potential problem in your logic structure or condition handling, resulting in unintended behavior. You can check following points. 
    1. Independent Triggers: Ensure that the visibility logic for the sections is not being triggered inadvertently by any change in the option set field. For example, if there’s any additional logic or an event listener in your form scripts that handles changes, they may cause this behavior.

    2. Else Block Condition: In your current code, the else block executes when platFormBased is not true. If there’s any unexpected change in the platFormBased value during the option set change, it may fall through to the else block and reveal both sections. Consider adding a more specific condition or an additional check to prevent this from happening.

    3. Field Dependencies or Triggering Events: Check if updating the option set field indirectly triggers the hideShowGeneralTabAndFields function through another event. You might want to explicitly isolate the conditions under which your form modification logic should runs.

    You can do something like this to further ensure isolation, you might want to explicitly restrict the section visibility logic to only execute when relevant:

     

    if (platFormBased === true) {
        // Logic for when platFormBased is true
        if (optionset === 11) {
            // BDC logic
            formContext.ui.tabs.get("General").sections.get("tab_10_section_1").setVisible(false);
            formContext.ui.tabs.get("General").sections.get("General_section_2").setVisible(true);
        } else if (optionset === 12) {
            // FUND logic
            formContext.ui.tabs.get("General").sections.get("tab_10_section_1").setVisible(false);
            formContext.ui.tabs.get("General").sections.get("General_section_2").setVisible(true);
        }
    } else {
        formContext.ui.tabs.get("General").sections.get("tab_10_section_1").setVisible(true);
        formContext.ui.tabs.get("General").sections.get("General_section_2").setVisible(false);
    }
     

    Cheers !

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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 258

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 164

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 121 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans