Recently, I came across a requirement where I had to do some calculation based on records added/deleted in sub-grid on CRM form. To achieve this, I have added load event on sub-grid in javascript where I could call the method which is doing the calculations.
Below piece of code will be used to add load event on sub-grid and function addEventToGridRefresh() should be registered on form load.
Here totalAssetsOfHousehold() is the actual method which is doing all the calculations. So whenever you add/delete record from sub-grid, totalAssetsOfHousehold() will be triggered.
thanks
p.
Below piece of code will be used to add load event on sub-grid and function addEventToGridRefresh() should be registered on form load.
function addEventToGridRefresh() {
// retrieve the subgrid
var grid = Xrm.Page.getControl('#GridControlName#');
// if the subgrid still not available we try again after 2 second
if (grid == null) {
setTimeout(function () { addEventToGridRefresh(); }, 2000);
return;
}
// add the function to the onRefresh event
Xrm.Page.getControl('#GridControlName#').addOnLoad(totalAssetsOfHousehold);
// This is used to delay refresh by 1 second because sometimes grid takes time to load.
// If you do not include below line, you may not see '+' and associate button on grid.
setTimeout(function () { Xrm.Page.data.refresh(); }, 1000);
}
Here totalAssetsOfHousehold() is the actual method which is doing all the calculations. So whenever you add/delete record from sub-grid, totalAssetsOfHousehold() will be triggered.
thanks
p.
Thanks Peeyush
ReplyDelete