Automatically Reloading the Fifth Sub-grid on a Form

CRM 2011 allows you to insert sub-grids to a form. Although there is no limit to number of sub-grids you can insert to the form, only the first four will be loaded automatically, there rest will appear with links “To load (sub-grid entity name) records, click here”.

Sub-grid

To load the fifth (and subsequent) sub-grid, execute the following JavaScript code on load of the form:

Prior to Update Rollup 12:


Xrm.Page.ui.tabs.get("tabName").sections.get("sectionName").controls.get("gridName").refresh();

If your CRM 2011 is later than Update Rollup 12, the code above will fail with error “Unable to get property ‘Refresh’ of undefined or null reference”.

The following code, though as not as elegant as the above, works. You need to call this function from the OnLoad event:


function InitialiseSubGrid() {
  var subGrid = document.getElementById("subGridName");
  if (subGrid == null || subGrid.readyState != "complete") {
    setTimeout('InitialiseSubGrid()', 2000); // retry in 2 seconds
    return;
  }
  subGrid.control.refresh();
};

Leave a comment