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

Notifications

Announcements

No record found.

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,983 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans