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

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

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    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/

  • PS10 Profile Picture
    8 on at

    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

  • Ram Prakash Duraisamy Profile Picture
    2,287 on at

    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

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

    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/

  • PS10 Profile Picture
    8 on at

    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

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