« Home | CrmDateTime conversion to DateTime » | Dynamic generation of Word(.DOCX) file » | Hiding CRM Elements » | CRM 5.0 Features » | Change the default entity in Lookup Window » | Multiple Column Sort in Dynamics CRM » | Display a Google Map for an Account » | ASP.NET Application Deployment Resources » | Visual Studio Error: The project file ' ' has been... » | Progress Bar in Dynamics CRM 4.0 »

Get selected item(s) in CRM grid

The following will retrieve an array containing the Id values of the selected records in the grid:
// get array of selected records
var a = document.all['crmGrid'].InnerGrid.SelectedRecords;
var selectedItems = new Array(a.length);
for (var i=0; i < a.length; i++)
{
selectedItems[i] = a[i][0];
}
alert(selectedItems);

//To get all of the records in the grid (ie. “All Records on Current Page”):
// array of all records on current page
var iTotal = document.all['crmGrid'].InnerGrid.NumberOfRecords;
var o = document.all['crmGrid'].InnerGrid;
var allItems = new Array;
var ii = 0;
for (var i=0; i < iTotal; i++)
{
allItems[ii] = o.rows[i].oid;
ii++;
}
alert(allItems);

Happy coding...

Labels: , , , , , , ,

Post a Comment