Archive

Archive for June 2, 2012

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