Monday, January 2, 2012

How to get Selected Rows of the grid Using JavaScript

Problem:

Need to get the selected rows values using JavaScript in MS CRM 2011.

Solution:

In my post "Retrieve rows in crm2011 subgrid with JScript" where I show you how to read all the rows of the subgrid in the Microsoft CRM 2011 using JavaScript. For this problem I will use same code but with some modification to get the rows which are selected by user. The code which is used to get the selected row detail is shown in List 1.

List 1

In the above code the only thing which is noticeable is the use of the get_selectedIds function of the grid control which will return the Ids of the selected rows, In this case the GUID of the record and then comparing the GUID with the original grid rows and if the Id is found mean row is selected and the each cell value is displayed of the selected row.

Anonymous: you can use code where you need it mean on load of the form or even on save of form if you want to get some data from grid ?Anonymous: Do you have same grid name as I have place mean "accountContactGrid" this grid is on account entity. In following post I have mention which name for grid is usedhttp://asimsajjad.blogspot.com/search/label/MS%20CRM%202011

As i am having the same problem, i tried to use above code "var number = Number(cellValue.replace(/[^0-9\.]+/g,""));" but, var number returns NaN. so it is not working for me. then i tried the below code i written using debbuger it is working for me.