I've tried JS option for summing a child entity in quotes but i seem to have an issue and it chucks up an error. I found the code from someone else doing the same as i was trying to do. The code is as follows
function setupGridRefresh() {
var targetgrid = document.getElementById("quotedetailsGrid");
// If already loaded
if (targetgrid.readyState == 'complete') {
targetgrid.attachEvent("onrefresh", subGridOnload);
}
else {
targetgrid.onreadystatechange = function applyRefreshEvent() {
var targetgrid = document.getElementById("quotedetailsGrid");
if (targetgrid.readyState == 'complete') {
targetgrid.attachEvent("onrefresh", subGridOnload);
}
}
}
subGridOnload();
}
function subGridOnload() {
//debugger;
var grid = Xrm.Page.ui.controls.get('quotedetailsGrid')._control;
var sum = 0.00;
if (grid.get_innerControl() == null) {
setTimeout(subGridOnload, 1000);
return;
}
else if (grid.get_innerControl()._element.innerText.search("Loading") != -1) {
setTimeout(subGridOnload, 1000);
return;
}
var ids = grid.get_innerControl().get_allRecordIds();
var cellValue;
for (i = 0; i < ids.length; i++) {
if (grid.get_innerControl().getCellValue('sb_itemweight', ids[i]) != "") {
cellValue = grid.get_innerControl().getCellValue('sb_itemweight', ids[i]);
cellValue = cellValue.substring(2);
cellValue = parseFloat(cellValue);
sum = sum + cellValue;
}
}
var currentSum = Xrm.Page.getAttribute('sb_totalowe').getValue();
if (sum > 0 || (currentSum != sum && currentSum != null)) {
Xrm.Page.getAttribute('sb_totalowe').setValue(sum);
}
}
The error that it brings when i load the form is Cannot read property 'readyState' of null at setupgridrefresh
I have double check to make sure all the names of fields and entitys are correct and can't find any issues.
Am i doing something silly here i believe this code was for 2013 have any of the principles changed
Cheers
Dan