Want to calculate INT values in form

Hello,
I want to calculate these two values in my form.
please guide me i am new in erpnext.
thank you in advance.

When i am trying this script getting this error please advise

test1

i have also tried cur_frm.set_value(“need_total_here”, cur_frm.doc.amount_1 + cur_frm.doc.amount_2);

Hi @shahid,

When would you like the total to be calculated? Eg. When the form loads or when you refresh the form, etc?
Try this, this will calculate the total whenever the form is refreshed or saved, if the fieldnames are as you mentioned in the screenshots above.

frappe.ui.form.on("Testing", "refresh", function(frm) {
	frm.set_value("need_total_here", frm.doc.amount_1 + frm.doc.amount_2);
}); 

i need values to be calculate when both of amounts values are filled.
means it should be calculate on onChange event.

@shreya115 thank you so much its working when i refresh my form.
now kindly help me to calculate it on when i enter both values not on refresh.
your efforts will be appreciated.

You can do something like this,

frappe.ui.form.on("Testing", {
	amount_1: function(frm) {
		calculate_total(frm);
	},

	amount_2: function(frm) {
		calculate_total(frm);
	}
});
var calculate_total = function(frm) {
    frm.set_value("need_total_here", frm.doc.amount_1 + frm.doc.amount_2);
}
1 Like

Thank you so much Shreya its working fine.