Skip to content

Instantly share code, notes, and snippets.

@rmehta
Created April 7, 2015 06:07
Show Gist options
  • Save rmehta/ff015c3be1f96d7109a3 to your computer and use it in GitHub Desktop.
Save rmehta/ff015c3be1f96d7109a3 to your computer and use it in GitHub Desktop.
Frappe Custom Script. Trigger on add row
frappe.ui.form.on("Z Item", {
"set_total": function(frm) {
var grand_total = 0;
$.each(frm.doc.z_items, function(i, d) { grand_total += d.qty; });
frm.set_value("grand_total", grand_total);
},
"z_items_add": function(frm, ) {
frm.events.set_total(frm);
},
"qty": function(frm) {
frm.events.set_total(frm);
}
});
@jschen889
Copy link

Sir, I use your script to calculate some total value of one child table. It can trigger the total field when I add row or update "cases" row. However, it can't trigger the total field when I remove(delete) a row. Could you please tell me how to solve this problem. My code is listed below.

frappe.ui.form.on("PI_Sale Item",{
"set_totalcase": function(frm) {
var tocases = 0;
$.each(frm.doc.pisaleitem, function(i, d) {
tocases += d.cases;}
);
frm.set_value("tocases", tocases);
refresh_field("tocases");
},
"cases": function(frm) {
frm.events.set_totalcase(frm);
},
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment