hi
this is for how we will retrieve subgrid data..
first create one entity and place it as subgrid in another entity
take the name of it.here "voter"
use the following code in main form onload.
function getVoterEligibility() {
debugger;
// var grid = document.getElementById("voter");
var grid = Xrm.Page.getControl("voter").getGrid();
if (grid == null) {
setTimeout(function () { getVoterEligibility(); }, 2000); //if the grid hasn’t loaded run this again when it has
return;
}
var totalCount = grid.getTotalRecordCount();
if (typeof totalCount == "number" && totalCount == 0) {
setTimeout(getVoterEligibility, 1000, "voter");
return;
}
else if (totalCount > 0) {
grid.getRows().forEach(function (row, index) {
var rowData = row.getData();
// $(rowData).css("background-color", "green")
if (rowData != null) {
var rowDataRef = rowData.getEntity().getEntityReference();
var id = rowDataRef.id;
var name = rowDataRef.name;
// alert(name);
var entityType = rowDataRef.entityType; //contact
//get entity
var entity = rowData.getEntity();
if (entity != null) {
//get primary attribute value
var entityPrimaryAttrValue = entity.getPrimaryAttributeValue();
//get subgrid record entity name
var entityName = entity.getEntityName();
//get entity Id
var entityId = entity.getId();
//get attributes displayed on subgrid row
var entityAttrbs = entity.getAttributes();
// var agevalue = entityAttrbs.get(1).getValue();
if (entityAttrbs.get(1).getValue() <= 20) {
$(grid.$3_1._element).find("tr[oid='" + id + "']").each(function () {
$(this).css("background-color", "green");
});
}
else {
$(grid.$3_1._element).find("tr[oid='" + id + "']").each(function () {
$(this).css("background-color", "Yellow");
});
}
//get entity reference
var entityRef = entity.getEntityReference();
}
}
});
}
}
this is for how we will retrieve subgrid data..
first create one entity and place it as subgrid in another entity
take the name of it.here "voter"
use the following code in main form onload.
function getVoterEligibility() {
debugger;
// var grid = document.getElementById("voter");
var grid = Xrm.Page.getControl("voter").getGrid();
if (grid == null) {
setTimeout(function () { getVoterEligibility(); }, 2000); //if the grid hasn’t loaded run this again when it has
return;
}
var totalCount = grid.getTotalRecordCount();
if (typeof totalCount == "number" && totalCount == 0) {
setTimeout(getVoterEligibility, 1000, "voter");
return;
}
else if (totalCount > 0) {
grid.getRows().forEach(function (row, index) {
var rowData = row.getData();
// $(rowData).css("background-color", "green")
if (rowData != null) {
var rowDataRef = rowData.getEntity().getEntityReference();
var id = rowDataRef.id;
var name = rowDataRef.name;
// alert(name);
var entityType = rowDataRef.entityType; //contact
//get entity
var entity = rowData.getEntity();
if (entity != null) {
//get primary attribute value
var entityPrimaryAttrValue = entity.getPrimaryAttributeValue();
//get subgrid record entity name
var entityName = entity.getEntityName();
//get entity Id
var entityId = entity.getId();
//get attributes displayed on subgrid row
var entityAttrbs = entity.getAttributes();
// var agevalue = entityAttrbs.get(1).getValue();
if (entityAttrbs.get(1).getValue() <= 20) {
$(grid.$3_1._element).find("tr[oid='" + id + "']").each(function () {
$(this).css("background-color", "green");
});
}
else {
$(grid.$3_1._element).find("tr[oid='" + id + "']").each(function () {
$(this).css("background-color", "Yellow");
});
}
//get entity reference
var entityRef = entity.getEntityReference();
}
}
});
}
}