Solved

MS CRM 2011 JScript Issue

Posted on 2013-01-21
3
465 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Microsoft Dynamics Management Reporter: When to Rebuild the Data Mart 1 368
dynamics crm 2013 1 101
Dynamics Crm 2016 4 86
crm development 2 105
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Desired Skill Set for Microsoft Dynamics CRM Technical Resources – Part I
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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