web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Help with Javascript OnLoad / Toggle Tab Visibility

(0) ShareShare
ReportReport
Posted on by

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); }
}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Royal King Profile Picture
    27,686 on at

    call the same function on load of the form as well that should take care of this issue.

  • Community Member Profile Picture
    on at

    Interesting, I swear I tried this exact thing and received an onload error.

    It's working now, thanks Chitrarasan.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans