Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Hide and show tabs based on text value

Posted on by 100
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
    Ami K 100 on at
    Hide and show tabs based on text value
    Thank youRudyZhang!
  • Suggested answer
    RudyZhang Profile Picture
    RudyZhang 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans