Help with Table Script

Hi :heart: , I have a problem with my script, what it does is sum “costos” column in the child table “costo” but it shows an error message about the syntax, but the syntax of the script is correct!

p

frappe.ui.form.on(“TestTable”, {
ctotal:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frm.doc.costo.forEach(function(d) { total += d.ctotal; });
frm.set_value(“costos”, total);
refresh_field(“costos”);
},
costo_remove:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frm.doc.costo.forEach(function(d) { total += d.ctotal; });
frm.set_value(“costos”, total);
refresh_field(“costos”);
}
});

share your script code…

sorry :stuck_out_tongue:, ready

try it…

frappe.ui.form.on("Costo", {
ctotal:function(frm, cdt, cdn){
var doc= locals[cdt][cdn];
var total = 0;
console.log(frm.doc);
cur_frm.doc.costo.forEach(function(d) { total += parseInt(d.ctotal); });
frm.set_value("costos", total);
refresh_field("costos");
},
costo_remove:function(frm, cdt, cdn){
var doc= locals[cdt][cdn];
var total = 0;
cur_frm.doc.costo.forEach(function(d) { total += parseInt(d.ctotal); });
frm.set_value("costos", total);
refresh_field("costos");
}
});
1 Like

i made a little changes and works perfectly! :heart: thanks

The final script for future consultations.

TableChild = Doctype of the child table
costo = the column that will be summed
table_2 = the table field on the parent doctype
total_01 = the float field where the total will be displayed

frappe.ui.form.on(“TableChild”, {
costo:function(frm, cdt, cdn){
var d= locals[cdt][cdn];
var total = 0;
cur_frm.doc.table_2.forEach(function(d) { total += d.costo; });
frm.set_value(“total_01”, total);
refresh_field(“total_01”);
},
table_2_remove:function(frm, cdt, cdn){
var d= locals[cdt][cdn];
var total = 0;
cur_frm.doc.table_2.forEach(function(d) { total += d.costo; });
frm.set_value(“total_01”, total);
refresh_field(“total_01”);
}
});