ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Table Total Sum on Field Doctype


#1

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…


#2
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.


#3

Hello Rohan,

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

See below:


#4

Hello Rohan,

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

See below:


#5

try put this above code on before_save.


#6

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?


#7

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


#8

Hi Ramesh,

This is the error log:


#9

@cyberdee
Did you specify some length to those fields?

like total_limbah length should be 2.