Show/ Hide header and ribbon menu dynamically on Dynamics 365/ Model Driven App forms

Recently I cam across a requirement from customer to control the header section visibility of Dynamics 365/ Model driven app form. For a very long time, Microsoft didn’t had any API’s to work with headers in model driven apps. You could work with controls on the header but if you had a requirement to show/ hide the header dynamically, there was no supported API for the same.

Now we have an API which allow you to do just that and in-fact much more. But before we go ahead and explore the API’s available, let’s explore the section of the header the API help us interact with.

There are primarily three methods which are important here.

  • getCommandBarVisible/ setCommandBarVisible
  • getBodyVisible/ setBodyVisible
  • getTabNavigatorVisible/ setTabNavigatorVisible

If you look at the above the screenshot, precisely these methods control the respective sections of the header. Below is how the form look when we use the function setCommandBarVisible to false.

formContext.ui.headerSection.setCommandBarVisible(false);

As you can see, the ribbon menu disappear when you pass false to this method. So if you are planning to show/ hide the ribbon menu dynamically, then you can use the setCommandBarVisible method.

Below is how the screen look when you use the function setBodyVisible and pass false to the function.

formContext.ui.headerSection.setBodyVisible(false);

As you can see from the above screenshot, the header and the primary name field are both hidden. So if you want to show/ hide header dynamically on Model driven app form, you can use the function setBodyVisible.

And now the final one – setTabNavigatorVisible.

formContext.ui.headerSection.setTabNavigatorVisible(false);

As seen from the above screenshot, the tab navigation is not visible. Precisely using the methods provided in the API you can do the following.

  • Show/ hide header and primary attribute section dynamically on Model driven app form/ Dynamics 365 form
  • Show/ hide ribbon menu dynamically on on Model driven app form/ Dynamics 365 form
  • Show/ hide tab navigation menu dynamically on Model driven app form/ Dynamics 365 form

You can explain similar API for the footer section as well.

Hope this helped!

Debajit Dutta
Business Solutions MVP