Write scripts for subgrids
Applies To: Dynamics CRM 2015
With Microsoft Dynamics CRM Online 2015 Update 1 you can do more with subgrid controls in forms by using new events and objects.
Important
For Microsoft Dynamics CRM Online organizations, this feature is available only if your organization has updated to Dynamics CRM Online 2015 Update 1. This feature is not available for Dynamics CRM (on-premises).
In this topic
Subgrid OnLoad event
Subgrid object model
Subgrid OnLoad event
Subgrids load asynchronously from the form so you can’t reliably get access to the data in the subgrid in the form OnLoad event. But you can set an event handler for the OnLoad event of the subgrid. This event will occur each time the data in the grid is refreshed, this includes when users sort the columns of the grid.
There is no user interface to add new event handlers for this event, so if you want to do so, you must use code in another event, typically the form OnLoad event to use the GridControl.27fea949-c332-4263-bb46-d990a18008b8#BKMK_subgridAddOnLoad method. To remove event handlers for this event, use the GridControl.27fea949-c332-4263-bb46-d990a18008b8#BKMK_subgridRemoveOnLoad method.
Subgrid object model
The diagram below shows the objects you can access from a subgrid in a form.
The subgrid control is referred to as a 27fea949-c332-4263-bb46-d990a18008b8#BKMK_GridControl in this context. As an Xrm.Page.ui control, the subgrid has all the methods available to all controls in addition to the 51828fe3-f6ff-4f97-80ed-b06b3a354955#BKMK_refresh method.
The 27fea949-c332-4263-bb46-d990a18008b8#BKMK_GridControl is the same object passed to a command bar or ribbon actions or rules using the <CrmParameter> (RibbonDiffXml) when available when the SelectedControl parameter is selected.
Change views with the ViewSelector
When a subgrid is configured to display a view selector you can get or set the current view. Use the GridControl.27fea949-c332-4263-bb46-d990a18008b8#BKMK_subgridGetViewSelector method to access the view selector and then the **ViewSelector.**27fea949-c332-4263-bb46-d990a18008b8#BKMK_ViewSelectorGetCurrentView27fea949-c332-4263-bb46-d990a18008b8#BKMK_ViewSelectorGetCurrentView and **ViewSelector.**27fea949-c332-4263-bb46-d990a18008b8#BKMK_ViewSelectorSetCurrentView methods to get or set the current view with a lookup object.
Get data from the grid
Use the GridControl.27fea949-c332-4263-bb46-d990a18008b8#BKMK_subgridGetGrid method to access the grid. Use the **Grid.**27fea949-c332-4263-bb46-d990a18008b8#BKMK_GridGetRows method or **Grid.**27fea949-c332-4263-bb46-d990a18008b8#BKMK_GridGetSelectedRows method to get a collection of 27fea949-c332-4263-bb46-d990a18008b8#BKMK_GridRow objects. You can then access a reference to each record in the row by chaining together the **GridRow.**27fea949-c332-4263-bb46-d990a18008b8#GridRowGetData, **GridRowData.**27fea949-c332-4263-bb46-d990a18008b8#BKMK_GridRowDataGetEntity, and **GridEntity.**27fea949-c332-4263-bb46-d990a18008b8#BKMK_GridEntityGetEntityReference methods.
See Also
Grid objects and methods (client-side reference)
Collections (client-side reference)
Write code for Microsoft Dynamics CRM forms
Write client application extensions
© 2016 Microsoft. All rights reserved. Copyright