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
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);
}
}
}
🙂
how to get schema name of subgrid
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/
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?
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
Does this work in CRM 2013?
I am trying to get the subgrid record count in crm 2011(RU15) and not even getting any error pls help me