Skip to main content

Notifications

Service | Customer Service, Contact Center, Fie...
Suggested answer

Hide Multiple Tabs with Java Script

Posted on by Microsoft Employee

I have a Case design that has multiple tabs. The tabs relate to the the value given in the Subject. I want the script to be able to hide all the tabs, and only display the tab that relates to the Subject value (I have created a Business Rule that maps the Subject value to the Description field).

The code below works OK but does not hide all the tabs when the form is loaded, then displays only the Subject 1 tab. It displays all the tabs once the form has loaded, then hides the specified tabs once the Subject has been set, leaving only the Subject 1 tab on display. It would work better if all tabs were hidden On Load, then only displayed the required tab once the Subject value has been set.

Could anyone who is skilled in jscript suggest a solution?

//Description: description
//To show/hide tab:
//Xrm.Page.ui.tabs.get("tab_system_name").setVisible(true/false);

function showHideTab() {
var Description = Xrm.Page.getAttribute("description").getValue() //Description: the trigger value
var showTab = true;
if (Description == "Subject 1") {
showTab = false;

}
Xrm.Page.ui.tabs.get("Subject 2_Details_Tab").setVisible(showTab);
Xrm.Page.ui.tabs.get("Subject 3_Details_Tab").setVisible(showTab);
Xrm.Page.ui.tabs.get("Subject 4_Details_Tab").setVisible(showTab);
}

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Hide Multiple Tabs with Java Script

    Hello Leah Ju

    Yes, that is correct, this works for one scenario only. I want to get the script that checks the rest of the scenarios, the If then Else part.

    The code below hides the unrequired tabs and then displays the required tab, based on the Subject value. I require the script that works when the Subject value changes.

    //Description: description

    //To show/hide tab:

    //Xrm.Page.ui.tabs.get("tab_system_name").setVisible(true/false);

    function showHideTabs() {

           var Description = Xrm.Page.getAttribute("description").getValue() //Description: the trigger value

    if (Description == "Subject 1") {

    }

    Xrm.Page.ui.tabs.get("Subject 1_Details_Tab").setVisible(true);

    Xrm.Page.ui.tabs.get("Subject 2_Details_Tab").setVisible(false);

    Xrm.Page.ui.tabs.get("Subject 3_Details_Tab").setVisible(false);

    Xrm.Page.ui.tabs.get("Subject 4_Details_Tab").setVisible(false);

    }

    Chris

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Hide Multiple Tabs with Java Script

    Hi Partner,

    As you  mentioned, "The code below works OK but not hide all the tabs when the form is loaded".

    Uncheck 'Visible by default' option can hide the tab when the form is loaded, then the js you added can work based on subject value to show tab you want.

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Hide Multiple Tabs with Java Script

    Hello Leah Ju

    Many thanks for your response. This doesn't seem to do what I was wanting. I want the control of the tab visibility to be based upon the value in the Subject field.

    So,

    If Subject = "Subject 1", then hide tabs Subject 2, Subject 3, Subject 4. Only display tab Subject 1.

    Else, if Subject = "Subject 2", then hide tabs Subject 1, Subject 3, Subject 4. Only display tab Subject 2.

    ...and so on.

    I am looking for the script to control the visibility of the tabs, based upon the Subject value, using an If then Else scenario.

    Chris

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Hide Multiple Tabs with Java Script

    Hi ChrisCroft,

    You can go Settings > Customizations > Customize the System > Entities > select one entity > Forms > open one form you need.

    Double-Click tab that you want to hide to open 'Tab Properties' dialog, and uncheck 'Visible by default' option.

    7824.pastedimage1629347046378v1.png

    For 'Related' tab, which is special, you need open 'form properties'and click on Display tab to uncheck the checkbox 'Show Navigation Items'.

    1460.pastedimage1629347463462v2.png

    Result:

    Before:

    3005.pastedimage1629347786850v4.png

    After:

    6765.pastedimage1629347613614v3.png

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,900 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,297 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans