Hello I made a function that detect if i added or deleted a new row in my subgrid and execute some coce according to that
Normally it works fine in an existing parent record unless I create a new parent record, i press save, then i add a row in my subgrid and my function executes twice for some reason
does anyone know why my code execute twice only when i create a new parent record, the function is in the onLoad even
I took the principle code from here :
function onLoad() {
var funtionName = "onLoad";
try {
setTimeout(function () {
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("contact_subgrid") != null && Xrm.Page.getControl("contact_subgrid") != undefined) {
_rowCount = Xrm.Page.getControl("subgrid").getGrid().getTotalRecordCount();
Xrm.Page.getControl("subgrid").addOnLoad(onGridLoad);
}
}, 5000);
} catch (e) {
Xrm.Utility.alertDialog(functionName + "Error: " + (e.message || e.description));
}
}
function onGridLoad() {
var functionName = " onGridLoad ";
var currentRowCount = null;
try {
setTimeout(function () {
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("contact_subgrid") != null && Xrm.Page.getControl("contact_subgrid") != undefined) {
currentRowCount = Xrm.Page.getControl("subgrid").getGrid().getTotalRecordCount();
if (currentRowCount > _rowCount) {
dosomething();
_rowCount = currentRowCount;
}
else if (currentRowCount < _rowCount) {
dosomethingelse();
_rowCount = currentRowCount;
}
}
}, 2000);
} catch (e) {
Xrm.Utility.alertDialog(functionName + "Error: " + (e.message || e.description));
}
}