Home > CRM 2011, JScript > Reading sub grid records using jscript in CRM 2011

Reading sub grid records using jscript in CRM 2011

Hi,

In CRM 2011, we can show the related records in parent record form using sub grids.

For example below is ‘Contacts’ sub grid on ‘Account’ form

Contacts sub-grid

Contacts sub-grid

We can get the records count and read the cell values of sub grid using below script.

function getSubGridDetails() {

// Set subgrid schema name

var subGridName = ‘accountcontactsgrid’;

if (document.getElementById(subGridName)) {

var gridControl = document.getElementById(subGridName).control;

// Get records length

var countGridRecords = 0;

if (gridControl && gridControl.getRecordsFromInnerGrid()) {

countGridRecords = gridControl.getRecordsFromInnerGrid().length;

alert(“Subgrid records count – ” + countGridRecords);

}

// Read Cell Values By Row

for (var indxRow = 0; indxRow < countGridRecords; indxRow++)

for (var indxCell = 0; indxCell < gridControl.getRecordsFromInnerGrid()[indxRow][3].cells.length; indxCell++) {

alert(“Cell Value – ” + gridControl.getRecordsFromInnerGrid()[indxRow][3].cells[indxCell].outerText);

}

}

}

🙂

Advertisement
  1. Namita
    July 10, 2012 at 12:22 PM

    how to get schema name of subgrid

  2. July 10, 2012 at 1:25 PM

    Hi,
    To get the sub grid schema name
    •Open the entity customization form
    •In designer, double click on subgrid
    •In the dialog window, copy the “Name” value
    Refer my previous blog
    https://rajeevpentyala.wordpress.com/2012/03/23/refreshing-sub-grid-and-main-grid-using-jscript-in-crm-2011/

  3. Namita
    July 10, 2012 at 1:29 PM

    Hey

    it will return the count of current view of sub grid and if i want all count of all record of the sub grid?

  4. July 10, 2012 at 2:42 PM

    With above approach you can only read records load on the page (i.e., Current grid view). To read whole records you need to make OData or SOAP retrieve call.Refer my artcicles on the same

  5. Rick
    May 30, 2014 at 9:56 AM

    Does this work in CRM 2013?

  6. Naveen
    February 7, 2016 at 1:14 AM

    I am trying to get the subgrid record count in crm 2011(RU15) and not even getting any error pls help me

  1. No trackbacks yet.

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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: