CRM2015 Update 1 – Grid methods

CRM2015 Update 1 has finally introduced the capability to manipulate/access grids in a supported way. The API methods are documented in https://msdn.microsoft.com/en-us/library/dn932126.aspx. However not all methods are documented. These are the additional methods that you can use, but not documented in msdn. The assumption is the subgrid is displaying the contact entity records.

Object GridRow Collection
Method get
Sample Usage
Xrm.Page
.getControl("GridControlName")
.getGrid()
.getRows()
.get(0)
Description Gets the row at the specified index in the grid
Object  GridRow Collection
Method  getByFilter
Sample Usage
Xrm.Page
.getControl("GridControlName")
.getGrid()
.getRows()
.getByFilter(function(r){
return r.getData()
.getEntity()
.getAttributes()
.getByName('fullname')
.getValue() === 'Max Power';
})
Description  Returns only the rows that have fullname attribute = Max Power
Object  GridRow Collection
Method  getFirst
Sample Usage
Xrm.Page
.getControl("GridControlName")
.getGrid().getRows()
.getByFilter(function(r){
return r.getData()
.getEntity()
.getAttributes()
.getByName('fullname')
.getValue() === 'Max Power';
})
Description  Returns only the 1st row that has fullname attribute = Max Power
Object  GridRow
Method  getKey
Sample Usage
Xrm.Page.getControl("GridControlName")
.getGrid()
.getRows()
.get(0)
.getKey()
Description  Return the primary key of the 1st row
Object  GridRow
Method  getId
Sample Usage
Xrm.Page
.getControl("GridControlName")
.getGrid()
.getRows()
.get(0)
.getData()
.getEntity()
.getId()
Description  Return the primary key of the 1st row
Object  Attribute
Method  getValue
Sample Usage
Xrm.Page.getControl("GridControlName")
.getGrid()
.getRows()
.get(0)
.getData()
.getEntity()
.getAttributes()
.getByName("fullname")
.getValue()
Description  Gets the value for the fullname attribute from the first row in the grid. If this attribute is not a grid column, this method will error as getByName will return null
Object  Grid
Method  openAssociatedGrid
Sample Usage
Xrm.Page.getControl("GridControlName")
.openAssociatedGrid()
Description  Opens the associated view, if it is in the navigation pane
Advertisement

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 )

Facebook photo

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

Connecting to %s