Table Total Sum on Field Doctype

Hello all…

I am an ernext user but not a programmer…so literally not understand coding or programming but willing to learn…

So, I created a child table called “Checksheet Proses Incinerator” and in the child table, there is two FLOAT data which called “jml_kemasan” and “jml_limbah” here is the table doctype:

I then created a doctype called “Checksheet Proses Incinerator” which I linked the “Checksheet Proses Incinerator” table onto the doctype. So I created a field called “total_kemasan” and “total_limbah” on my “Checksheet Proses Incinerator” doctype.
here is my doctype:

I would like to summarize the total one or two data (either the “total_kemasan” and “total_limbah”) on my “Checksheet Proses Incinerator” doctype - at the “total_kemasan” or “total_limbah” field… but unfortunately my code didn’t work… is there somebody who could help?

Here is my code:

frappe.ui.form.on("Checksheet Proses Incinerator", "validate", function(frm,doc) {
     var total = 0
     $.each(frm.doc["jml_kemasan"] || [], function(i, d) {
         total += d.total_kemasan
     });
     frm.set_value('sum_total_kemasan', total);
});

Thank you in advance…

frappe.ui.form.on("Checksheet Proses Incinerator", "validate", function(frm,doc) {
    var total_kemasan=0;
    var total_limbah=0;
    for(var i=0;i<cur_frm.doc.table.length;i++){
        total_kemasan+=cur_frm.doc.table[i].jml_kemasan;
        total_limbah+=cur_frm.doc.table[i].jml_limbah;
    }
    cur_frm.set_value("total_kemasan",total_kemasan);
    cur_frm.set_value("total_limbah",total_limbah);
    cur_frm.refresh_fields("total_kemasan");
    cur_frm.refresh_fields("total_limbah");
});

I hope this script solve your problem.

Hello Rohan,

Thank you for the code, but unfortunately it didn’t work on my side…the doctype cannot be saved…

See below:

Hello Rohan,

Thank you for the code, but unfortunately it didn’t work on my side…the doctype cannot be saved…

See below:

try put this above code on before_save.

Still no luck… Btw i changed the field doctype of total_jumlah and total_limbah from data/read only into float. Is this affecting the code?

No,try to debug the script by putting console.log and what value are coming.

Hi Ramesh,

This is the error log:

@cyberdee
Did you specify some length to those fields?

like total_limbah length should be 2.

still no luck…