Asked by:
How to get selected record values in subgrid using javascript in MS CRM 2013

General discussion
-
Hi,
we are using MS CRM 2013 online.
in this i want to retrieve selected record values in a subgrid.
please find the below screenshot.
in this i want to retrieve product abc and abcd values using javascript.
can anyone help us to solve the requirement.
Thanks in Advance
Chandra
Saturday, November 23, 2013 11:15 AM
All replies
-
Hi,
You could try to use below code :
function RetrieveSubGridRecords() {
var grid = document.getElementById("SubGridName").control;
for (var rowNo = 0; rowNo < grid.GetRecordsFromInnerGrid().length; rowNo++)
for (var cellNo = 0; cellNo < grid.GetRecordsFromInnerGrid()[rowNo][3].cells.length; cellNo++)
alert(grid.GetRecordsFromInnerGrid()[rowNo][3].cells[cellNo].outerText);
}
Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
Vikram !Saturday, November 23, 2013 12:31 PM -
Hi Vikarm,
Thanks for your reply.
I am using below code but it is giving error.
var grid = document.getElementById("Products1").control;
can you please suggest me.
Thanks in Advance
Chandra
Saturday, November 23, 2013 12:43 PM -
Hi Chandra,
What event you are using to attach this function ?
Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
Vikram !Saturday, November 23, 2013 1:21 PM -
Onload Event,
Below is the script.
function RetrieveSubGridRecords() {
var grid = document.getElementById("Product1").control;
for (var rowNo = 0; rowNo < grid.GetRecordsFromInnerGrid().length; rowNo++)
for (var cellNo = 0; cellNo < grid.GetRecordsFromInnerGrid()[rowNo][3].cells.length; cellNo++)
alert(grid.GetRecordsFromInnerGrid()[rowNo][3].cells[cellNo].outerText);
}in this i added onload event to the form with function RetrieveSubGridRecords.
Saturday, November 23, 2013 3:05 PM -
Ah, actually your code is executing before loading the sub grid records.
Please try this :
function RetrieveSubGridRecords() {
if (document.getElementById("Product1")) {
var grid = document.getElementById("Product1").control;
for (var rowNo = 0; rowNo < grid.GetRecordsFromInnerGrid().length; rowNo++)
for (var cellNo = 0; cellNo < grid.GetRecordsFromInnerGrid()[rowNo][3].cells.length; cellNo++)
alert(grid.GetRecordsFromInnerGrid()[rowNo][3].cells[cellNo].outerText);
}
else {
setTimeout("RetrieveSubGridRecords();", 2500);
}
}Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
Vikram !Saturday, November 23, 2013 3:34 PM -
Thanks Vikram.
It's working now.
Sunday, November 24, 2013 5:28 PM