Here are the steps
The ShowTab function is added to the onchange event of a Boolean field.
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