RE: Subgrid OnChange event for JavaScript
Hi,
the below is my code
//copy from here
var totalrecordonload;
function onLoad()
{
try {
//setting timeout beacuse subgid take some time to load after the form is loaded
setTimeout(function () {
//validating to check if the sub grid is present on the form
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("Contacts") != null && Xrm.Page.getControl("Contacts") != undefined) {
//stores the row count of subgrid on load event of CRM Form
totalrecordonload = Xrm.Page.getControl("Contacts").getGrid().getTotalRecordCount();
//registering refreshform function onload event of subgrid
Xrm.Page.getControl("Contacts").addOnLoad(SetSubgridOnLoad);
}
}, 5000);
} catch (e)
{
Xrm.Utility.alertDialog(functionName + "Error: " + (e.message || e.description));
}
}
function SetSubgridOnLoad()
{
try {
//setting timeout beacuse subgid take some time to load after the form is loaded
setTimeout(function () {
//validating to check if the sub grid is present on the form
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("Contacts") != null && Xrm.Page.getControl("Contacts") != undefined) {
//stores the row count of subgrid on load event of CRM Form
var aftertotal = Xrm.Page.getControl("Contacts").getGrid().getTotalRecordCount();
if (totalrecordonload != aftertotal )
{
alert("Total Record Onload " + totalrecordonload + " after deleted " + aftertotal);
totalrecordonload = aftertotal ;
Xrm.Page.data.refresh(false);
}
else
{
}
}
}, 5000);
} catch (e)
{
Xrm.Utility.alertDialog(functionName + "Error: " + (e.message || e.description));
}
}
//copy until here
you can take a look on below video, how it works in my environment.
https://youtu.be/8pqIprEmQ7c