Hide and Show Tab in Dynamics 365 CRM Using JavaScript
Hide and Show Tab in Dynamics 365 CRM Using JavaScript
Dynamics 365 CRM provides flexible form customization capabilities that allow developers to control the visibility of tabs, sections, and fields based on business requirements. One common requirement is dynamically showing or hiding tabs depending on field values or user selections.
Using JavaScript, you can create intelligent forms that display only relevant information to users, resulting in a cleaner user interface and improved productivity.
Business Scenario
Suppose a Customer Type option set contains:
- Individual
- Business
When Business is selected, a tab named "Business Information" should become visible. Otherwise, the tab should remain hidden.
Benefits of Dynamic Tab Visibility
- Cleaner user interface
- Improved user experience
- Reduced user confusion
- Faster data entry
- Better form organization
Create JavaScript Function
function hideShowTab(executionContext)
{
var formContext =
executionContext.getFormContext();
}
Get Field Value
var customerType = formContext.getAttribute( "new_customertype" ).getValue();
Show or Hide Tab
if(customerType == 100000001)
{
formContext.ui.tabs.get(
"tab_businessinfo"
).setVisible(true);
}
else
{
formContext.ui.tabs.get(
"tab_businessinfo"
).setVisible(false);
}
Register the JavaScript
- Create a JavaScript Web Resource.
- Upload the script.
- Add the library to the form.
- Register the function on Form OnLoad.
- Register the function on Field OnChange.
- Save and Publish customizations.
Hide Tab on Form Load
formContext.ui.tabs.get( "tab_businessinfo" ).setVisible(false);Important: Register the function on both OnLoad and OnChange events to ensure the tab visibility updates correctly when records are opened and modified.
Common Use Cases
- Customer onboarding forms
- Vendor management processes
- Project management applications
- Employee onboarding systems
- Service request forms
- Approval workflows
Benefits
- Dynamic form behavior
- Improved productivity
- Better user experience
- Reduced clutter
- Enhanced data quality
Key Takeaways
- JavaScript can dynamically control tab visibility.
- Tabs can be shown or hidden based on field values.
- Creates cleaner and more user-friendly forms.
- Improves form usability and navigation.
- Widely used in Dynamics 365 CRM customizations.