CRM Crate

Get row data from the Sub-Grids in Dynamics 365

We will learn to get row data from the Sub-Grids in Dynamics 365 CRM. Before we start, make sure to subscribe to CRM Crate so that you stay up-to-date in field of Dynamics 365.

Get row data from the Sub-Grids in Dynamics 365

What are Sub-Grids in Dynamics 365?

You can configure a sub-grid on a form to display a list of records or a chart. The Sub-Grid properties can be accessed in the solution explorer. Under Components, expand Entities, expand the entity you want, and then select Forms. In the list of forms, open the form of type Main. Then on the Insert tab, select Sub-Grid to view sub-grid properties.

Click on the given link to understand more about the Sub-Grids –

Why do we need to retrieve data from the Sub-Grids?

Consider a business scenario where we have to get the data from a particular Sub-Grid row (record) and perform a dedicated set of operations with the retrieved row data. We can achieve this requirement with help of the below given procedure.

Using GridRowData (Client API reference) for getting row data –

We will use the GridRowData client API to retrieve the row data using the client side JavaScript.

GridRowData (Client API reference)

GridRowData also provides methods for retrieving information specific to a record displayed in an editable grid row, including a collection of all the columns included in the row.

JavaScript snippet code for getting row data –

The below JavaScript snippet is triggered during the OnChange event of form field. For demonstration purpose, we have stored the values obtained from the Sub-Grid rows in a new form field.

//CRM Crate - JavaScript Snippet
function CallMethod (executionContext) {
var Data = "";

//Initiating Form Context.
var formContext = executionContext.getFormContext();

//Retrieving Value From Field.
var Input = formContext.getAttribute("cc_getgriddata").getValue();
if(Input == true)

//Collecting Subgrid Context.
var gridContext = formContext.getControl("CRM_Crate_Subgrid");

//Collecting Subgrid Rows.
var myRows = gridContext.getGrid().getRows();

//Obtaining Total Row Count.
var RowCount = myRows.getLength();

//Iterating Through Subgrid Rows.
for (var i = 0; i < RowCount; i++) {

//Obtaining A Single Row Data.
var gridRowData = myRows.get(i).getData();

//Obtaining Row Entity Object.
var entity = gridRowData.getEntity();

//Collecing Row EntityRefrence.
var entityReference = entity.getEntityReference();

//Adding Up Row Data In A Variable.
Data += +"\n";

//Setting Value In Field.
else if(Input == false)

//Clearning Value Of Field.

Validate the output in Dynamics 365 form –

Once the above JavaScript code is deployed, navigate to the Dynamics 365 CRM and validate the result as shown below.

Thus we learned to get row data from the Sub-Grids in Dynamics 365.

5 1 vote
Article Rating
Notify of

Newest Most Voted
Inline Feedbacks
View all comments
S Shah
11 months ago

very useful article, thank you so much

2 months ago

Very informative Article. Thank You so much.

error: CRM Crate Security Engine - Disabled Right Click & Selection!


Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.