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 – https://www.crmcrate.com/feeds/create-configure-sub-grid-in-form-crm-dynamics-365-form-customization/

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 += entityReference.name +"\n";
}

//Setting Value In Field.
formContext.getAttribute("cc_displaydata").setValue(Data);
}
else if(Input == false)
{

//Clearning Value Of Field.
formContext.getAttribute("cc_displaydata").setValue("");
}
}

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 2 votes
Article Rating
Subscribe
Notify of
7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
S Shah
2 years ago

very useful article, thank you so much

Ramya
2 years ago

Very informative Article. Thank You so much.

Peter
1 year ago

That is a pretty good article. Thanks for sharing. I have one question, how do i get the values of the cells extracted. For Example I would like to have as well the payment-status.

User 23
1 year ago

why it is not showing all 14 records? how to see all of them

Lokesh
1 year ago
Reply to  User 23

Yeah, I am having same doubt.

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

Congratulations!

Well Done,
Welcome to CRM Crate

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