Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS CRM 2011 JScript Issue

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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.
Desired Skill Set for Microsoft Dynamics CRM Technical Resources – Part I
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

705 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