You are currently viewing Hide/Show Tab Based on Attribute in Dynamics 365 Customer Engagement
Hide Show Tabs 3

Hide/Show Tab Based on Attribute in Dynamics 365 Customer Engagement

To hide or show a tab based on a Boolean field, use a javascript web resource function. The following is a function to use. It is based on the execution context of the change event and a tab name passed during the change event.

Here are the steps

This is the function to add as a web resource. The function creates a namespace ensuring the unique name of the functions within the javascript web resource.

The ShowTab function is added to the onchange event of a Boolean field.

The parameters passed are the execution context as the first parameter and the tab name. The JavaScript function verifies the existence of the tab on the form, and depending on the value of the Boolean field, hides or displays the tab. I also like hiding the tab as a default. This keeps the tab hidden while the page loads without having the “Now you see it, now you don’t” effect.

But wait… what about when the page loads. Should the tab display?

An onload function will work in this case with an adjustment to the function. Along with receiving the Execution context, we could pass in the field name and the tab name. Alter the function to get the value of the passed in field name. Of course, check if the field is present on the form.

That should do it.

What’s that — you have multiple fields and tabs?

You could add the load event as many times as you need it changing the parameters to the correct values. Or Just pass in an array to the function. Nope — that will not work.

We’ll have to create a new function to handle the arrays. This function will run as an onload event. The new function will accomplish two things. First, it will check the value of the tab field to display the tab then create an on-change event adding a function to test the value and hide/show the tab. The function uses a for loop to iterate the field and tab names in the parameter array. And finally, if more fields/tabs are added the only change needed is in the onload event.

Here is the code:

Add the arrays to the event handler, ensure you check the “Pass execution context as first parameter” checkbox.

Got questions? Contact us!

By Sanford Mosby, Senior Technical Consultant, Dyn365Pros, Microsoft Dynamics 365 Partner, San Diego, Southern California