Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS CRM 2011 JScript Issue

Posted on 2013-01-21
3
Medium Priority
?
471 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 20

Assisted Solution

by:Rikin Shah
Rikin Shah earned 2000 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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

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
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

916 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