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

}

}

}

🙂

Advertisements
Advertisements

6 responses to “Reading sub grid records using jscript in CRM 2011”

  1. Namita Avatar
    Namita

    how to get schema name of subgrid

  2. Rajeev Pentyala Avatar

    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 Avatar
    Namita

    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. Rajeev Pentyala Avatar

    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 Avatar
    Rick

    Does this work in CRM 2013?

  6. Naveen Avatar
    Naveen

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

Leave a comment