Hi,
I created the same scenario from my end where I used contact subgrid in account entity.
Note: Please Change the field name as per yours
It works for me
function GetTotalYesCount(executionContext) {
var execContext = executionContext;
var formContext = executionContext.getFormContext();
var idqualifyyescount = 0;
var sowbomyescount= 0;
var scopeyescount= 0;
var closeyescount= 0;
try {
//get rows - use the getControl method and pass the grid name.
//var gridContext = formContext.getControl("Contacts");
if(formContext.getGrid().getTotalRecordCount() == 0){
setTimeout(function () { GetTotalYesCount(execContext); }, 2000);
return;
}
var allRows = formContext.getGrid().getRows();
//loop through rows and get the attribute collection
allRows.forEach(function (row, rowIndex) {
//get the attribute Collection
var attributeColl = row.getData().getEntity().attributes;
attributeColl.forEach(function (att, attrIndex) {
switch (att.getName()) {
case "new_twooption":
if (att.getValue() == true) { //att.getValue() == "Yes"
idqualifyyescount = idqualifyyescount +1;
}
break;
case "new_twooption1":
if (att.getValue() == true) {
sowbomyescount = sowbomyescount +1;
}
break;
case "new_twooption2":
if (att.getValue() == true) {
scopeyescount = scopeyescount +1;
}
break;
case "new_twooption3":
if (att.getValue() == true) {
closeyescount = closeyescount +1;
}
break;
}
});
});
if ((idqualifyyescount + sowbomyescount + scopeyescount +closeyescount) > 4) {
Xrm.Utility.alertDialog("More than 4 Yes's have been entered in the Sales Quota Distribution.");
}
}catch(err){
console.log('Error occurred :' + err)
}
}
function testCase(executionContext){
var formContext = executionContext.getFormContext();
formContext.getControl("Contacts").addOnLoad(GetTotalYesCount);
}
that testCase function is called in Form Onload event of Account in my case(Check as per yours)