web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

How to hide tabs based on field value

(0) ShareShare
ReportReport
Posted on by 35

I have this code created but want to add to it for if the same field is another value, show another tab. How do I add conditions to what I already have? 

function Industry() {
//show Construction tab if the Account Type = Construction and the Sub Type = Public
var AccountTypeValue = Xrm.Page.getAttribute("accountypecode").getValue();
var SubTypeValue = Xrm.Page.getAttribute("grey_subtype").getValue();

var industrytab = Xrm.Page.ui.tabs.get("IndustryTab");

if (SubTypeValue != null && SubTypeValue == 3) {

//show the section
industrytab.setVisible(true);
}
else {
//hide the section
industrytab.setVisible(false);
}
}

this code works but I need another condition where if account type = public sector show a public sector tab. I know it’s the same script but how do I include this script within the existing script. Anything I try gives me an error as it is outside the function

I have the same question (0)
  • Suggested answer
    shivaram Profile Picture
    3,315 on at

    Hi,

    Will it be any issue if you are writing else if condition? There is no option to optimize the code. And I would recommend don't use Xrm.Page as its deprecated

  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hi,

    I am not sure how it is working. You are missing Account Type = Construction check condition in your code.

    As per your comment - //show Construction tab if the Account Type = Construction and the Sub Type = Public

    but in your check condition you are only checking subtype

    if (SubTypeValue != null && SubTypeValue == 3) {

    I hope this is not intentional and happened by mistake.

    Now coming to your original question where you would like to add another codnition to show Public tab - I have modified your code as below, please try this -

    function Industry(executionContext) {

    var formContext=executionContext.getFormContext();

    //show Construction tab if the Account Type = Construction and the Sub Type = Public

    var AccountTypeValue = formContext.getAttribute("accountypecode").getValue();

    var SubTypeValue = formContext.getAttribute("grey_subtype").getValue();

    var industrytab = formContext.ui.tabs.get("IndustryTab");

    var publictab = formContext.ui.tabs.get("PublicTab");

    if (SubTypeValue != null && SubTypeValue == 3) {

    //show the section

    industrytab.setVisible(true);

    // Hide Public Tab

    publictab.setVisible(false);

    }

    else if(AccountTypeValue!=null && AccountTypeValue==Specify Public Optionset valie)

    {

    industrytab.setVisible(false);

    publictab.setVisible(true);

    }

    else {

    //hide the section

    industrytab.setVisible(false);

    publictab.setVisible(false);

    }

    }

    You are also missing 't' in accountypecode field schema name. Please verify this anfd fix your schema name.

    Make sure to select pass execution context as first parameter when you register your event handler.

    CR46.PNG

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Suggested answer
    Vipin J Profile Picture
    1,603 on at

    Generic Method to Hide and Show Tab and Section  - https://vjcity.blogspot.com/2021/07/generic-method-to-hide-and-show-tab-and.html

    How to hide a section in MS CRM 2016 based on user logged in ?  - https://vjcity.blogspot.com/2016/09/how-to-hide-section-in-ms-crm-2016.html

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    Please go through below link you will get some idea.

    juniorcrmblog.blogspot.com/.../how-to-hide-and-show-tab-based-on.html

    juniorcrmblog.blogspot.com/

    www.youtube.com/.../videos

    Thanks,

    Arshad

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 60 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 43

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans