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

Show/Hide Tabs based on a lookup value

(0) ShareShare
ReportReport
Posted on by 8

Hi, 

I have a requirement to show/hide tabs based on different lookup values, I have implemented the below code since XRM.... is now deprecated, i am getting no errors, alert will take me to true condition however, the tab is not hiding, I am not a developer(code copied from internet) and we are on-premise d365crm

The tabs are laid as shown below:

pastedimage1639054184525v1.png

I have added script on Form(On Load) and on the lookup field (OnChange):

function showHideTabs(executionContext) { alert(1);
formContext = executionContext.getFormContext();
var tabObj = formContext.ui.tabs.get("Tab B");

if(formContext.getAttribute("new_profiletype").getValue()[0].name=="Individual")

{ alert(2);

tabObj.setVisible(false);

}

else

{ alert(3);

tabObj.setVisible(true);


}

}

Thanks,

PS

  • PS10 Profile Picture
    8 on at
    RE: Show/Hide Tabs based on a lookup value

    Hi Bipin,

    Thats right the code was working in the first instance i realised the issue was not with the code, infact later i found out that we have so many other scripts so i decided to move my script on top of others and code worked.

    Thanks for all your efforts.

    I am now struggling to reload the page automatically as tabs will hide however i have to manually refresh the page to be able to see the changes, i am using the below but not working, it only saves the data but doesnt refresh:

    formContext.data.refresh(true);

    Thanks,

    PS

  • Suggested answer
    Bipin D365 Profile Picture
    28,961 Moderator on at
    RE: Show/Hide Tabs based on a lookup value

    Hi,

    I have tried below code on my instance and it is working as expected.

    function showHideTabs(executionContext) { alert(1);
    formContext = executionContext.getFormContext();
    var tabObj = formContext.ui.tabs.get("tab_2");

    if(formContext.getAttribute("msft_emergencycontact").getValue()[0].name=="Anand Mahindra")

    { alert(2);

    tabObj.setVisible(false);

    }

    else

    { alert(3);

    tabObj.setVisible(true);


    }

    }

    CR5.PNG

    CR6.PNG

    CR7.PNG

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Ram Prakash Profile Picture
    2,287 on at
    RE: Show/Hide Tabs based on a lookup value

    Hello PS10 

    1. First get the Tab Name (Navigate to https://make.powerapps.com then Click Tables --> Click Forms --> Open Main Form --> Click On Tab you will get Name of the Tab)

    2. Write Below JS for Showing or Hiding the Values

    function showOrHideTabBasedOnLookupValue(executionContext){

    var formContext = executionContext.getFormContext();

    var tabObj = formContext.ui.tabs.get("Tab Name");

    if(formContext.getAttribute("new_profiletype").getValue()!=null && formContext.getAttribute("new_profiletype").getValue()[0].name=="Individual"){

    tabObj.setVisible(false);

    }

    else{

    tabObj.setVisible(true);

    }

    Please mark as Answer if it is helpful and provide Kudos


    Subscribe : www.youtube.com/.../UCnGNN3hdlKBOr6PXotskNLA
    Blog : microsoftcrmtechie.blogspot.com

  • PS10 Profile Picture
    8 on at
    RE: Show/Hide Tabs based on a lookup value

    Hi Bipin,

    that is just the typing mistake, I didn't pay attention while giving the example.

    In the actual code as you said, i have given the Tab name and not the display name and no space.

    So query still remains to why it wont work, i have also tried old XRM code that too doesn't give error but for some reason won't hide the tabs:

    function hideTab() {

    if(Xrm.Page.getAttribute("ofs_profiletype")!=null && Xrm.Page.getAttribute("ofs_profiletype").getValue()!=null && Xrm.Page.getAttribute("ofs_profiletype").getValue()[0].name=="Individual")

    {

    Xrm.Page.ui.tabs.get("tab_B").setVisible(false); //hide

    }

    else

    {

    Xrm.Page.ui.tabs.get("tab_B").setVisible(true); //show

    }

    }

    Thanks,

    PS

  • Suggested answer
    Bipin D365 Profile Picture
    28,961 Moderator on at
    RE: Show/Hide Tabs based on a lookup value

    Hi,

    var tabObj = formContext.ui.tabs.get("Tab B");

    You need to give tab name not display name as highlighted in below screen. There should not be any space between tab name.

    CR4.PNG

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,272 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,927 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans