Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Sum values from Subgrid with if statement

$
0
0

Hello,

I'm having some difficult getting this code to execute properly. I am trying to total the Quantity field from the subgrid based on the product type. So when a sales rep is entering in opportunity products a field below the subgrid would show the total units. I only want the field to sum the quantity of products with the value of software or hardware. I get odd behavior back with the below code. If I have the if statement point to just one product type i.e "Software" the summed value is returned as 0. If I use the or statement "Software" || "Hardware" the summed value totals everything thing in the subgrid not just the hardware or software items. Below is my code. Any help is greatly appreciated.

function UnitsTimeout(){
 setTimeout(calcUnits, 1500);
}
function calcUnits() {
var grid = document.getElementById('opportunityproductsGrid'); 
var ids = grid.control.get_allRecordIds();
var sum = 0.00;
for(i = 0; i < ids.length; i++) {
  if(grid.control.getCellValue('producttypecode',ids[i]) == "Software" || "Hardware") {
  var cellValue = grid.control.getCellValue('quantity',ids[i]);
  var number = Number(cellValue.replace(/[^0-9\.]+/g,""));
  sum = sum + number;
}
}
Xrm.Page.data.entity.attributes.get("new_itemssold").setValue(sum);
Xrm.Page.data.entity.attributes.get("new_itemssold").setSubmitMode("always");
}


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>