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 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

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans