How to Hide/Show Tab Based on Condition in Dynamics?

How to Hide/Show Tab Based on Condition in Dynamics?

In this blog, users can learn how to hide/show tabs based on some condition or values in entity form using javascript in Dynamics 365.

Here in Contact entity Type is field. And we have 1 tab in the form labeled as Types of Contact. So when the Type field contains data at that time, Tab should be visible, and if it doesn’t contain data, then keep that tab hidden.

Follow the below steps to hide/show the tab in the form.

Step 1: First, we will create one JS file and write the code as below.

new_type: Is a Logical name of field.

type_contact: It’s a unique name of a tab which we want to hide or show.

function hideShowTab() {
var type = Xrm.Page.getAttribute("new_type").getValue();
if (type != “”) {
window.parent.Xrm.Page.ui.tabs.get("type_contact").setVisible(true);
}
else {
window.parent.Xrm.Page.ui.tabs.get("type_contact").setVisible(false);
}
}

➢ So here we create a function hideShowTab, which we will call on loading of the form.

➢ In this function, firstly, we get the value from field(Type), and then if it contains data, then show the Type Of Contact tab. Else we hide the tab

Step_1

Step 2: Now create 1 JScript webresource in CRM and upload the above js. Save & Publish it.

Step_2

Step 3: Now open the entity form from the solution and set form properties.

➢ Open the contact entity’s form.

Step_3

➢ Set form properties.

Step_4

➢ To set Form Properties click on Form Properties highlighted in the above image.

➢ It will open a pop-up with the Events tab.

➢ We need to add Form Library, click on Add and add a newly created webresource(new_hideshowtab).

Step_5

➢ Now scroll down, set our library, and function on loading of form events.

  • Control: Select Form here.
  • Event: Choose OnLoad.
Step_6

➢ Click on Add to add the library and function name which we want to be called on the loading of the form.

➢ Now click on OK.

Step 4: Save and Publish the form.

Step_7

➢ Now open the contact and check the case. If the Type field has value, then Tab should be visible. Otherwise, it will be hidden.

➢ Here we open a record for Alex in which the Type is null then the tab will be hidden.

Step_8

➢ In Carla’s record, Type has a value, then the tab (Type of Contact) will be visible.

Step_9

This is how users can configure form properties and hide/show tabs based on different conditions.

All product and company names are trademarks™, registered® or copyright© trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.

Riddhi Faldu

Riddhi Faldu

Riddhi is a firm believer of serenity and writing is something that keeps her grounded. Being a Computer Engineer by qualification, understanding and writing about tech comes to her naturally. It wouldn't be wrong to call her diligent as she likes pushing herself and others to bring the best on table. In leisure time, she likes practicing calligraphy and wishes to master the beautiful concoction of ink and words.

Read Related Blogs About Dynamics 365 Portal

How to Clear the Cache in the Power Apps Portal

How to Clear the Cache in the Power Apps Portal

3 Min
Revolutionizing Financial Services with Dynamics 365 Customer Portal

Revolutionizing Financial Services with Dynamics 365 Customer Portal

5 Min
Why You Need D365 Developers in Your Team

Why You Need D365 Developers in Your Team

4 Min
To Top