Solved

MS CRM 2011 JScript Issue

Posted on 2013-01-21
3
463 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a walkthrough guide I wrote whilst upgrading my on-premise MS Dynamics CRM 3.0 deployment to 4.0. This covers the actual installation of the product to a working level for my system, I ran into a lot of issues that the steps below fixed so h…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

831 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