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);
}
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?
for me same error continues
Hi PMM001,
I created a Yes/No type field(Form Type) to test your code. It works fine. Below is my code:
onload event:
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:
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:
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?
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 :)
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
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,524 Super User 2024 Season 2
Martin Dráb 228,469 Most Valuable Professional
nmaenpaa 101,148