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();
};

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s