Many times we have requirements to read sub grid records and
do subtotal or some others stuff with grid data. Here is same code to retrieve
entire rows and columns from SubGrid.
function RetrieveSubGridRecords() {
if (document.getElementById("SubGridName")) {
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);
}
else {
setTimeout("RetrieveSubGridRecords();", 2500);
}
}
Hope it helps. J
Vikram, nice post, How can we find the subgridname on the Account form??
ReplyDeleteI tried bunch of option but no luck.
I have a requirement that is easier, I just need to check if there are ANY records in the grid and if it is empty (no associated records) I need to display and error message. How would that look? Thanks.
ReplyDeleteThe code is unsupported as it uses GetElementById...
ReplyDeletevar x = window.parent.document.getElementById("SubGridName").control;
ReplyDeletethis returns me "undefined" when getting to use this code on 2015 online.
anyone have an work around? I want to code to work on 2015 on-premise so I cann't use the resent subgird methods given to 2015 online version.
this will work on dynamics crm online
ReplyDeletevar ctrl = Xrm.Page.getControl(SubgridName);
var selectedRows = ctrl.getGrid().getSelectedRows();
var selectedRow = selectedRows.getAll()[0];
var recordId = selectedRow.getData().getEntity().getEntityReference().id;
var attributes = selectedRow.getData().getEntity().getAttributes().getAll();
attributes.forEach(function (attribute) {
console.log(attribute.getKey() + "|" + attribute.getValue());
});
is it work with crm 2016?
ReplyDelete