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 :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

How to hide tabs using java script

(0) ShareShare
ReportReport
Posted on by 5

Can anyone help please ?

I have search other similar queries but still cannot get a working answer.

On a Form there is a field (Form Type) which has 2 choices.  I want to show/hide tabs (Tab_3, Tab_4 and Tab_5) depending on the option selected - hide all three or show all three.  The original script was hoping to OnLoad (of the form) hide all three tab, and then OnChange of the field show or hide depending on the option.

Whatever I have tried I get the error "Cannot read properties of undefined (reading 'getFormContext') - I have tried changing so may parts of the script - cutting it right down to just OnChange and just one Tab - still not working.

This is the code as it is now

function ToggleTab(executionContext) {
var formContext = executionContext.getFormContext();

var tabvalue = formContext.getAttribute("crm365_formtype").getValue();
formContext.ui.tabs.get("tab_5").setVisible(false);
formContext.ui.tabs.get("tab_3").setVisible(false);
formContext.ui.tabs.get("tab_4").setVisible(false);

if (tabvalue == 154220000)
formContext.ui.tabs.get("tab_5").setVisible(true);
formContext.ui.tabs.get("tab_3").setVisible(true);
formContext.ui.tabs.get("tab_4").setVisible(true);

if (tabvalue == 154220001)
formContext.ui.tabs.get("tab_5").setVisible(false);
formContext.ui.tabs.get("tab_3").setVisible(false);
formContext.ui.tabs.get("tab_4").setVisible(false);
}

I have the same question (0)
  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    from the error my best guess is that the option "pass execution context as first parameter" has not been checked when you attached the javascript functions to the onload and onchange events

  • PMM001 Profile Picture
    5 on at

    No that was ticked - believe it or not I suddenly remembered something from years ago - changed the function name to begin with a lowercase and the error went away.  Need more tweaking to get it fully working but sorted now :)

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi PMM001,

    I created a Yes/No type field(Form Type) to test your code. It works fine. Below is my code:

    onload event:

    Snipaste_5F00_2022_2D00_02_2D00_08_5F00_09_2D00_25_2D00_07.png

    function hideAllTabs(executionContext) { 
    	var formContext = executionContext.getFormContext();
            formContext.ui.tabs.get("tab_5").setVisible(false);
    	formContext.ui.tabs.get("tab_4").setVisible(false);
    	formContext.ui.tabs.get("tab_3").setVisible(false);
    }
    
    

    onchange event on Form Type field:

    Snipaste_5F00_2022_2D00_02_2D00_08_5F00_09_2D00_27_2D00_27.png

    function ToggleTab(executionContext) { 
    	var formContext = executionContext.getFormContext();
    
    	var tabvalue = formContext.getAttribute("cr2f9_formtype").getValue();
    	formContext.ui.tabs.get("tab_5").setVisible(false);
    	formContext.ui.tabs.get("tab_3").setVisible(false);
    	formContext.ui.tabs.get("tab_4").setVisible(false);
    
    	if (tabvalue){
    		formContext.ui.tabs.get("tab_5").setVisible(true);
    		formContext.ui.tabs.get("tab_3").setVisible(true);
    		formContext.ui.tabs.get("tab_4").setVisible(true);
    	}else if (!tabvalue){
    		formContext.ui.tabs.get("tab_5").setVisible(false);
    		formContext.ui.tabs.get("tab_3").setVisible(false);
    		formContext.ui.tabs.get("tab_4").setVisible(false);
    	}
    }
    
    

    Result:

    tab.gif

    You could check the setting as the screenshot shows. If they are correct, please check whether there are any other event handler on your table and is it correct?

  • ONE BEE Profile Picture
    15 on at

    for me same error continues

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Your initial code missing some curly brackets. Can you pleas provide your current version of the code and screen that demonstrates how you registered the event handler?

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 > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 62 Most Valuable Professional

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Pallavi Phade Profile Picture

Pallavi Phade 49

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans