Child table name for Sewing is “Costing Table3”
Child table name for Labels is “Costing Table4”
Child table name for Trims and Accessories is “Costing Table5”
So, I want to calculate the total of all the fields of Sewing and display it in “ttl1”, Labels total in “ttl2” and trim/accessories in “ttl3”
frappe.ui.form.on("Costing Template", {
validate: function(frm) {
// this function is called when the record is saved
update_totals(frm);
}
});
function update_totals(frm) {
var total2 = 0;
// calculate total of each line in sewing
// assuming your child table name (not that of the doctype, that of the table) is sewings
frm.doc.sewings.forEach(function (item) {
var ttl1 = item.threads + item.elastic1 + item.elastic2;
item.ttl1 = ttl1;
total2 += ttl1;
});
// do the same for the other child tables
// apply total 2
cur_frm.set_value("total2", total2);
}
The extension looks good, can you please check your browser console (press F12) and share error messages? There might be some error in the script… If it does not save this correlates with the fact that this insert is added in the validate block, an error will prevent saving…