Dynamics 365 — How to Get Row Data From Sub-Grids
In this post, I will show you how to get row data from the subgrids in Dynamics 365. Subgrids are useful for displaying related records on a form, such as contacts for an account or tasks for an opportunity. But sometimes, you may want to access the data of the subgrid rows in your code, for example, to perform some calculations or validations. Fortunately, with the help of javascript we can easily do that.
One way to get row data from the subgrids is to use the getGrid() method of the Xrm.Page.getControl function. This method returns a Grid object that has a getRows() method, which returns a collection of GridRow objects. Each GridRow object has a getData() method, which returns a GridEntity object that contains the data of the row. You can use the getEntity() methods of the GridEntity object to access the entity and its attributes.
Let’s see an example of how to use this approach. Suppose you have a subgrid on the account form that shows the related opportunities. You want to write a function that calculates the total estimated revenue of all the opportunities in the subgrid and displays it in an alert message.
Here is how you can get row data from Sub-grids:
Step by step explanation:
- This function gets the subgrid control by its name, which you can find in the form editor.
- Then, it checks if the subgrid is loaded and gets its rows.
- Next, it loops through each row and gets its data, entity and attributes.
- It then adds the value of the estimated revenue attribute to a variable that stores the total.
- Finally, it displays the total in an alert message.
This is one way to get row data from the subgrids in Dynamics 365. I hope you found this post helpful and informative. If you have any questions or feedback, please leave a comment below.