30 Dec’16

Dynamics 365, EnterpriseUnderstanding Subgrid functions in CRM Online

Using the new subgrid functions, there are 2 ways to get count of the subgrid data. Based on requirement, we have to use one or the other way for achieving the requirement.


It determines the total no. of records that match the filter criteria of the view.

1. The count is NOT limited by the current page size. You will get the total size across all pages.
2. You may not also get the latest count of the records using this function if new records are added on the subgrid.

How to get around #2 above to get correct count:

  1. The idea is to make the grid refresh before executing the “getTotalRecordCount” function, which will enable us to get the correct count.
  2. We also have to add an onload event handler for the grid control. Whenever grid is refreshed through code or manually, the onload function will trigger.
  3. Note that we cannot do this without onload event. If we try to execute “getTotalRecordCount” just after the refresh line without onload event handler, you will get an error as the grid refresh happens asynchronously and it may not be ready.

Sample Code

 var myContactsGridOnloadFunction = function () {  
     console.log("Contacts Subgrid OnLoad occurred"); 
     var count = Xrm.Page.getControl("Contacts").getGrid().getTotalRecordCount();   

/// bind an onload event to the grid control  


/// refresh the grid. This will trigger onload event.  



getRows() will return collection of all gridrows in the grid.

1. It will only return the rows currently visible on the grid.
2. getRows().getLength() will return the count of rows currently visible
3. Unlike getTotalRecordCount, we need not refresh the grid to get the correct row length using this function.


  1. In cases, where we want to know if the grid is empty we can use “getRows().getLength()” instead of getTotalRecordCount to know if the count is 0 or Not.

Sample code:

var rows = Xrm.Page.getControl(opptyProductSubGridName).getGrid().getRows(); 
var rowLength = rows.getLength();
Written by

Team Member


Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.

Want to streamline your business processes?

  • This field is for validation purposes and should be left unchanged.

Recent Articles

  • Dynamics 365 Client Diagnostics

    15 March’ 2018

    Main cause of Performance Issues: Bandwidth and latency are the primary characteristics which affects the performance o...

    Read more
  • Closing Blind Shift in MPOS and CPOS in Dynamics 365 for Retail

    15 March’ 2018

    Manual For closing Blind shift in POS: Blind shifts terminate the currently ongoing shift and when logged in a new shif...

    Read more
  • Persistent Filters in the Power BI Service

    13 March’ 2018

    Introduction: The feature is finally release, and it is power BI has announced general availability of persistent filt...

    Read more
  • Cause and Solution for Scribe MSMQ not receiving Message from AX

    10 March’ 2018

    Issue: Microsoft Message Queuing (MSMQ) service running on Server might be unable to receive messages. Therefore, messa...

    Read more
  • User Privileges on SharePoint – D365 Document Integration

    10 March’ 2018

    Overview: Often, we wonder what could be wrong where we see a generic error on Documents in Dynamics 365. Something lik...

    Read more