Retrieve Subgrid rows in CRM 2011 using JScript

Posted: May 25, 2012 in CRM 2011, Jscripts

Getting all the rows of a Subgrid in CRM 2011

At times we need to get Subgrid row values in crm .  By using Related Contacts subgrid in Account entity.

Following is the example to get all the subgrid records of Related Contacts in Account entity.

function GetSubGridRows() {
   var grid = document.getElementById("accountContactsGrid").control;
   for (var rowNo = 0; rowNo<grid.getRecordsFromInnerGrid().length; rowNo++)
      for (var cellNo = 0; cellNo<grid.getRecordsFromInnerGrid()[rowNo][3].cells.length; cellNo++)
         alert(grid.getRecordsFromInnerGrid()[rowNo][3].cells[cellNo].outerText);
}

Get only Selected records in Subgrid in CRM 2011

Here is the Jscript code to get only selected rows in subgrid

function GetSubGridSelectedRows() {
    var grid = document.getElementById("accountContactsGrid").control;
     for (var rowNo = 0; rowNo < grid.get_selectedRecords().length; rowNo++) {
        alert(grid.get_selectedRecords()[rowNo].Id);
        alert(grid.get_selectedRecords()[rowNo].Name);
    }
}
Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s