locked
CRM 2013: Show/Hide a subgrid in Form onLoad RRS feed

  • Question

  • I have put a subgrid on a form. This is shown or hidden according to a field value on the form.

    The onChange code I have on the field works fine, but the same code in the onLoad causes an error.

    Xrm.Page.getControl("mysubgrid") is null.

    How can I get access to the subgrid control in the onLoad?

    Tuesday, November 18, 2014 1:48 PM

Answers

  • you can add a setTimeout in order to check for the subgrid

    function GridEvent(gridName) {
       // retrieve the subgrid
       var grid = Xrm.Page.getControl(gridName);
       // if the subgrid still not available we try again after 1 second
       if (grid == null) {
           setTimeout(function () {GridEvent(gridName);}, 1000);
           return;
       } else {
         // your code here
       }
    }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Proposed as answer by HIMBAPModerator Tuesday, November 18, 2014 4:36 PM
    • Marked as answer by STHook Wednesday, November 19, 2014 1:43 PM
    Tuesday, November 18, 2014 4:28 PM

All replies

  • The proper way would be:-

    As all grids are child entities therefore you should use oData (retreivemultiple) and check child entity count and show hide the grid based on count.


    Regards Faisal

    Tuesday, November 18, 2014 4:22 PM
  • you can add a setTimeout in order to check for the subgrid

    function GridEvent(gridName) {
       // retrieve the subgrid
       var grid = Xrm.Page.getControl(gridName);
       // if the subgrid still not available we try again after 1 second
       if (grid == null) {
           setTimeout(function () {GridEvent(gridName);}, 1000);
           return;
       } else {
         // your code here
       }
    }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Proposed as answer by HIMBAPModerator Tuesday, November 18, 2014 4:36 PM
    • Marked as answer by STHook Wednesday, November 19, 2014 1:43 PM
    Tuesday, November 18, 2014 4:28 PM
  • That worked! Thank you.
    Wednesday, November 19, 2014 1:44 PM