How to get sum of field from child table

Hi,

I am fairly new to scripting and need to get a total square footage from a child table.

I got an example to calculate square footage from another post, and just need to be able to get the sum of all the entries.

frappe.ui.form.on(“quotesection”, “length”, function(frm, cdt, cdn){
var d = locals[cdt][cdn];
frappe.model.set_value(d.doctype, d.name, “sqft”, d.length * d.width);
});

frappe.ui.form.on(“quotesection”, “width”, function(frm, cdt, cdn){
var d = locals[cdt][cdn];
frappe.model.set_value(d.doctype, d.name, “sqft”, d.length * d.width);
});

Any help would be greatly appreciated.

frappe.ui.form.on("quotesection", "width", function(frm, cdt, cdn){
  var d = locals[cdt][cdn];
  frappe.model.set_value(d.doctype, d.name, "sqft", d.length * d.width);

  var total = 0;
  frm.doc.quotesection.forEach(function(d) { total += d.sqft; });

  frm.set_value('total_sqft', total);

});
5 Likes

Thank you very much for such a quick response. Exactly what I was missing.

2 Likes