Solved

MS CRM 2011 JScript Issue

Posted on 2013-01-21
3
461 Views
Last Modified: 2013-02-12
Hi guys

Been working with MS Dynamics v4 for a while now and have begun some work on 2011 and have run into a problem getting my head around how the JScript works now and hope someone can help.

On the Contact form I have added a JScript Form Library and have added the following code into it:

function setVisibleTabSection(tabname, sectionname, show) {
    var tab = Xrm.Page.ui.tabs.get(tabname);
    if (tab != null) {
        if (sectionname == null)
            tab.setVisible(show);
        else {
            var section = tab.sections.get(sectionname);
            if (section != null) {
                section.setVisible(show);
                if (show)
                    tab.setVisible(show);
            }
        }
    }
}

Open in new window


As you'll see it's a simple show Tab/Section function that has been around for some time. However I'm having a problem getting it to work on my form.

Within my form I have a field and I want the Tab to appear/disappear on the selection of the Yes/No boolean field that I have added (by default it is NULL).

So on my form I have added the following Event Handler to my field:

JScript Added
Within the Parameters section I have ticked the 'Pass execution context as first parameter' as well and when I open a Contact and click the No button I get an erro message like this:

Error Message about sections
The Tab on my form has a label of Volunteer but I know I need to pass the name (tab3) to the function. I'm also aware I can show/hide Sections as well but I believe that if I say NULL then all Sections in the Tab should appear (correct me if I'm wrong of course please).

I'm curious if I'm doing this the correct way as I'm too used to simply adding/altering the code directly in the form/field and working this way. I know this will make life a lot simplier but I need to find my way past the first hurdle and any help is greatly appreciated as always guys.

Thanx
0
Comment
Question by:Steven O'Neill
  • 2
3 Comments
 
LVL 19

Assisted Solution

by:Rikin Shah
Rikin Shah earned 500 total points
ID: 38801179
Hi,

You need to pass the section name. Or in this case, as per my understanding you want to hide/show all sections... then go for this code-

Change this code as per your need-
function toggleSectionDisplayState(tab, show) {
    //Hide or Show Sections 
    var tabs = Xrm.Page.ui.tabs.get(tab);
        tabs.sections.forEach(function (section, index) {
                section.setVisible(show);
    }
}

Open in new window

0
 
LVL 2

Accepted Solution

by:
Steven O'Neill earned 0 total points
ID: 38863416
Sorry I didn't come back to this sooner but I ended up using this code:

function SetControlInvisible(tabName, dependantField) {
    //get control for field
    var control = Xrm.Page.ui.tabs.get(tabName);
    //get control for dependant field
    var dependantControl = Xrm.Page.ui.controls.get(dependantField);
    var attribute = dependantControl.getAttribute();
    var depandantFieldValue = attribute.getValue();
    //set visible based on depandant fields value
    if (depandantFieldValue == false) {
        control.setVisible(false);
    }
    else {
        control.setVisible(true);
    }
}

Open in new window

0
 
LVL 2

Author Closing Comment

by:Steven O'Neill
ID: 38879429
My solution works for me but the code provided by rikin_shah would suffice for a different issue
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

On Sep 22nd 2014 Microsoft released Update Rollup 1 for Microsoft Dynamics CRM 2013 Service Pack 1 and back in July Update Rollup 3 was released.  So we now have:   Update Rollup 1Update Rollup 2Update Rollup 3Service Pack 1Update Rollup 1 for S…
Automatically creating a Trello card using data from a Microsoft Dynamics CRM record turned out to be an easy project that yielded great results.  Here's how I did this for an internal team at General Code.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now