The purpose of this script is to toggle visibility of two different tabs based on the value of an option set on a field on the Case form.
The code I have so far does exactly what I want, however when the form is reloaded both tabs are again visible.
I would like for this script to trigger not only when the field is selected on the form, but when the form is loaded as well. I am having trouble finding the proper syntax for the OnLoad JavaScript event.
The two tabs I want to toggle the visibility on are
- 'tabCom'
- 'tabRes'
The following option set values mean have 'tabCom' visible.
- 100000000
- 100000002
The following option set values mean have 'tabRes' visible.
- 100000001
- 100000003
If option is 'NULL' I want to hide both sections.
-----------------------------------------------
var tabExpand = {};
tabExpand.expandCollapseTab = function () {
var expand = Xrm.Page.getAttribute('urs_rooftypelist').getValue();
if (expand == '100000000') {
Xrm.Page.ui.tabs.get('tabCom').setDisplayState('expanded');
Xrm.Page.ui.tabs.get('tabRes').setDisplayState('collapsed');
Xrm.Page.ui.tabs.get('tabCom').setVisible(true);
Xrm.Page.ui.tabs.get('tabRes').setVisible(false);
} else if (expand == '100000001') {
Xrm.Page.ui.tabs.get('tabCom').setDisplayState('collapsed');
Xrm.Page.ui.tabs.get('tabRes').setDisplayState('expanded');
Xrm.Page.ui.tabs.get('tabCom').setVisible(false);
Xrm.Page.ui.tabs.get('tabRes').setVisible(true);
} else if (expand == '100000002') {
Xrm.Page.ui.tabs.get('tabCom').setDisplayState('expanded');
Xrm.Page.ui.tabs.get('tabRes').setDisplayState('collapsed');
Xrm.Page.ui.tabs.get('tabCom').setVisible(true);
Xrm.Page.ui.tabs.get('tabRes').setVisible(false);
} else if (expand == '100000003') {
Xrm.Page.ui.tabs.get('tabCom').setDisplayState('collapsed');
Xrm.Page.ui.tabs.get('tabRes').setDisplayState('expanded');
Xrm.Page.ui.tabs.get('tabCom').setVisible(false);
Xrm.Page.ui.tabs.get('tabRes').setVisible(true);
} else if (expand == null) {
Xrm.Page.ui.tabs.get('tabCom').setDisplayState('collapsed');
Xrm.Page.ui.tabs.get('tabRes').setDisplayState('collapsed');
Xrm.Page.ui.tabs.get('tabCom').setVisible(false);
Xrm.Page.ui.tabs.get('tabRes').setVisible(false); }
}