Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Hide and show tabs based on text value

(0) ShareShare
ReportReport
Posted on by 27
Hi everyone,
 
On an OnLoad event for a Form, I have the following expression which works for hiding a tab and showing a different tab based on the value of a text field.
 
function HideTabOne() {   if(Xrm.Page.getAttribute(/column_logical_name/).getValue() == /Test 1/) {       Xrm.Page.ui.tabs.get(/tab_one/).setVisible(false);   }   else {       Xrm.Page.ui.tabs.get(/tab_two/).setVisible(true);   }}
 
How could I add an additional condition to this expression so that if the text field equals /Test 2/, then tab_one should be visible, and tab_two should be hidden?
 
Best regards,
 
  • Ami K Profile Picture
    27 on at
    Hide and show tabs based on text value
    Thank youRudyZhang!
  • Suggested answer
    RudyZhang Profile Picture
    Microsoft Employee on at
    Hide and show tabs based on text value
    Hi,
     
    Regarding the issue that you want to hide or show the tabs according to certain conditions
     
    Our team has modified the code you provided to meet your needs, the modified code is as follows.
    function HideTab() {
        var textFieldValue = Xrm.Page.getAttribute('column_logical_name').getValue();
        
        if (textFieldValue === 'Test 1') {
            Xrm.Page.ui.tabs.get('tab_one').setVisible(false);
            Xrm.Page.ui.tabs.get('tab_two').setVisible(true);
        } else if (textFieldValue === 'Test 2') {
            Xrm.Page.ui.tabs.get('tab_one').setVisible(true);
            Xrm.Page.ui.tabs.get('tab_two').setVisible(false);
        }
     }
    In this code above, we store the value of the text field in a variable called textFieldValue to improve readability. Then, we added an additional if condition to check if the value is equal to "Test 2". If it is, tab_one is set to visible and tab_two is set to hidden. You can adjust the "Test 1" and "Test 2" values to meet your business needs.
     
    I hope my answer is helpful to you! If you have any other questions, please feel free to contact me.
     
    Best Regards,
    Rudy Zhang

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 181 Super User 2025 Season 1

#2
Siv Sagar Profile Picture

Siv Sagar 149 Super User 2025 Season 1

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 124 Super User 2025 Season 1

Product updates

Dynamics 365 release plans