Skip to main content

Notifications

Announcements

No record found.

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
    PS10 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
    Bipin D365 28,959 Super User 2024 Season 1 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
    Ram Prakash 2,285 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
    PS10 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
    Bipin D365 28,959 Super User 2024 Season 1 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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans