In my Opportunity form, I've added a Sales Quota Distribution Grid (See screenshot below). If more than four Yes's have been entered in the entire grid, I want a warning message (or something similar) to be shown. For example, in the screenshot below, the "svc, Azure" account has 4 fields marked "Yes". The "XXXX, XXXX" account has zero. If I change one the distributions next to "XXXX, XXXX", I want the warning message to appear.
I'm trying to create a JavaScript event to get this functionality to work. However, I don't have much JavaScript experience and could use some help getting this to work. Here is what I have so far:
function GetTotalYesCount() {
var selectedRow = null;
var attributeColl = null;
var idqualifyyescount;
var sowbomyescount;
var scopeyescount;
var closeyescount;
var selectedRow = null;
var attributeColl = null;
var idqualifyyescount;
var sowbomyescount;
var scopeyescount;
var closeyescount;
try {
//get the selected rows - use the getControl method and pass the grid name.
selectedRow = Xrm.Page.getControl("s_qd").getGrid().getSelectedRows();
selectedRow = Xrm.Page.getControl("s_qd").getGrid().getSelectedRows();
//loop through rows and get the attribute collection
selectedRow.forEach(function (row, rowIndex) {
selectedRow.forEach(function (row, rowIndex) {
//get the attribute Collection
attributeColl = row.getData().getEntity().attributes;
attributeColl = row.getData().getEntity().attributes;
switch (att.getName()) {
case "new_idqualify":
case "new_idqualify":
if (att.getValue() = "Yes") {
idqualifyyescount = idqualifyyescount +1;
case "new_sowbom":
idqualifyyescount = idqualifyyescount +1;
case "new_sowbom":
if (att.getValue() = "Yes") {
sowbomyescount = sowbomyescount +1;
}
case "new_scope":
sowbomyescount = sowbomyescount +1;
}
case "new_scope":
if (att.getValue() = "Yes") {
scopeyescount = scopeyescount +1;
}
case "new_close":
scopeyescount = scopeyescount +1;
}
case "new_close":
if (att.getValue() = "Yes") {
closeyescount = closeyescount +1;
}
}
closeyescount = closeyescount +1;
}
}
if ((idqualifyyescount + sowbomyescount + scopeyescount +closeyescount) > 4) {
Xrm.Utility.alertDialog("More than 4 Yes's have been entered in the Sales Quota Distribution.");
}
Xrm.Utility.alertDialog("More than 4 Yes's have been entered in the Sales Quota Distribution.");
}
}
}
}
}
}
}
}
Am I on the right track? Any help getting this to work would be greatly appreciated. Thanks in advance!!