Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

How to hide a subgrid...

Posted on by 2,645

I have a tab, and in this tab I have 1 question which is called, "nhs_performanceguarantees_y_n_b"

I also have a subgrid in this tab.  I am trying to hide this subgrid which is called, "RFP_Guarantee" when nhs_performanceguarantees_y_n_b contains a No, null, blank, undefined.

So if the field is a Yes I want the subgrid to show, if anything else hide it.  Below is my script thus far and I can't get it to work. 

function GuaranteesonChange()
 {
  var Guarantees = Xrm.Page.getAttribute("nhs_performanceguarantees_y_n_b").getValue();
   if (Guarantees == null || Guarantees == 'undefined' || Guarantees == '' || Guarantees == 'No')
   {
    Xrm.Page.getControl("RFP_Guarantee").setVisible(false);
   }
  else
   {
    Xrm.Page.getControl("RFP_Guarantee").setVisible(true);
   }
 }

Any  help is appreciated, thank you.

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to hide a subgrid...

    Paste this function in the Javascript Library added on the form and Add "HideGrid" function on Form Load Event.

    function HideGrid()

    {

       var new_performanceguarantees=Xrm.Page.getAttribute("nhs_performanceguarantees_y_n_b");

       if (new_performanceguarantees != null && new_performanceguarantees.getValue() != null) {

           if (new_performanceguarantees.getValue() == "Yes") {

              Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(false);

           }

           else {

             Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(true);

           }

       }

    }

    Please mark as answer if it helps you.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: How to hide a subgrid...

    I am not sure I completely understand you business case, but the first question is what type of control is nhs_performanceguarantees_y_n_b?

    There are two cases that you might need to call this function, in the form load and in the change event of the above control. This should be able to cover all your cases. You can modify your change even to be more specific:

    function GuaranteesOnChange()

    {

       var Guarantees = Xrm.Page.getAttribute("nhs_performanceguarantees_y_n_b").getValue();

       switch (Guarantees)

       {

          case 'Yes':

                Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(true);

                break;

          case 'No':

                Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(false);

                break;

          default: // All Other Cases

                Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(false);

                break;

       }

    }

    In your onLoad event of the form add the following line:

    GuaranteesOnChange(); // Check the value of the performanceguarantees control, and show/hide section/subgrid

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to hide a subgrid...

    If I select Yes and then select the blank option form my drop down field, the subgrid does hide and then comes back when No or Yes is selected again, which isn't correct.

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to hide a subgrid...

    This doesn't seem to work. I put in the below:

    function GuaranteesonChange()

    {

     var Guarantees = Xrm.Page.getAttribute("nhs_performanceguarantees_y_n_b").getValue();

      if (Guarantees == null || Guarantees == 'undefined' || Guarantees == '' || Guarantees == 'No')

      {

         Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(false);

      }

     else

      {

         Xrm.Page.ui.tabs.get("tab_Guarantees").sections.get("tab_Guarantees_sec_Guarantees").setVisible(true);

      }

    }

    So when the form loads I have this entire tab hiding.  When another field is filled in then the tab shows (this part is working fine).  Now in the tab I have a field, which by default it appears as -- (meaning it is blank, null).  The grid shows when this happens.  I need the subgrid to not show when this happens.

    Thank you.

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: How to hide a subgrid...

    Just use the function that you created:

    function GuaranteesonChange()

     {

      var Guarantees = Xrm.Page.getAttribute("nhs_performanceguarantees_y_n_b").getValue();

       if (Guarantees == null || Guarantees == 'undefined' || Guarantees == '' || Guarantees == 'No')

       {

          Xrm.Page.ui.tabs.get("tabName").sections.get("sectionName").setVisible(false);

       }

      else

       {

          Xrm.Page.ui.tabs.get("tabName").sections.get("sectionName").setVisible(true);

       }

     }

    In your form designer, on the field that you want to capture the change, click on Change Properties.

    On the Events tab (after you have added the JavaScript library as a web resource and to the form), in the Event Handlers section click Add, and select the JavaScript library and enter the function Name (No need to pass execution context).

  • USA80 Profile Picture
    USA80 2,645 on at
    RE: How to hide a subgrid...

    So what would the hole thing look like then?   meaning where would I place that in the above script?

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: How to hide a subgrid...

    The easiest way is if the subgrid is on a section by its own to hide the section.

    Xrm.Page.ui.tabs.get("tabName").sections.get("sectionName").setVisible(false);

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans