How to get the sum of the two fields in the same form using custom script? Can you explain me the code on how to do it? Iβm new in erpnext.
frappe.ui.form.on("doctype_name", "validate", function(frm) {
frm.set_value("field3", frm.doc.field1 + frm.doc.field2);
})
The above code will set sum of field1 and field2 in field3 on saving of the form.
1 Like
Hi THANK YOU VERY MUCH ! itβs a big help. Still, can I auto-calculate it without saving the form?
Following code will calculate field3, on change of field1 / field2:
frappe.ui.form.on("doctype_name", "field1", function(frm) {
frm.set_value("field3", flt(frm.doc.field1) + flt(frm.doc.field2));
})
frappe.ui.form.on("doctype_name", "field2", function(frm) {
frm.set_value("field3", flt(frm.doc.field1) + flt(frm.doc.field2));
})
4 Likes
Wow β¦ Thank you very much β¦ however, there is a logical error, the field3 displays wrong output, like i input on the field1 β1β and the field2 β1β, it displays β11β on the field3.
Its working now! Thank you so much sir!
1 Like
Fieldtype of of all the fields should be Int / Currency / Float. Seems like you have set it as Data.