CRM 2013 Subgrid JavaScript Operations

Hello everyone,

In this article I will share some code snippets to help you work with CRM 2013 Subgrid Javascript Operations.

Get cell value from a Subgrid using JavaScript in CRM

The javascript code below helps us to get a cell value from a crm subgrid control.


var gridControl = document.getElementById('subgrid_id').control;
var ids = gridControl.get_allRecordIds();
for (i = 0; i < ids.length; i++) {
    var cellValue = gridControl.getCellValue('column_name', ids[i]);
    // DO WHATEVER YOU WANT WITH THE CELL VALUE HERE!..
}

First line: we get the subgrid control via its id.
Second line: We get all the records inside the subgrid.
Third line: We go through the for loop and get the cell values. Inside this loop you can catch the value you desired and process it.

 Get Subgrid with JavaScript

Using below javascript code line you can get a crm subgrid.

// Get Subgrid
var jj_subGrid = Xrm.Page.ui.controls.get("jj_ContactsGrid");

 

Hide Subgrid with JavaScript

// For hiding
jj_subGrid.setVisible(false);

Show Subgrid with JavaScript

// For Showing
jj_subGrid.setVisible(true);

 

Get Visibility of Subgrid with JavaScript

// For Checking If it the subgrid is Visible or Hidden
jj_subGrid.getVisible();

 

In this post I tried to mention important javascript code snippets which I find useful when I work with crm subgrids.

I hope you find this post useful too.

See you 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *