I have been working on a Dynamics 2011 CRM form where I am attempting to hide a tab and its sections from the onload event. Even though my code runs without any errors, the tab always remains visible. It seems like the custom code I wrote works initially but then gets overridden by some other built-in code that resets the tab to be visible again. There are no other custom scripts present on this particular form.
function onLoad() {
debugger;
try {
var formType = Xrm.Page.ui.getFormType();
var myTab = Xrm.Page.ui.tabs.get("document");
if (formType == 1) {
var mySec = myTab.sections.get("documentInstructionSection");
mySec.setVisible(true);
mySec = myTab.sections.get("documentDetailsSection");
mySec.setVisible(false);
myTab.setVisible(false);
Xrm.Page.ui.tabs.get("document").setVisible(false);
}
else {
var mySec = myTab.sections.get("documentInstructionSection");
mySec.setVisible(false);
mySec = myTab.sections.get("documentDetailsSection");
mySec.setVisible(true);
}
}
catch (err) {
}
}