Refresh Value from Custom Field

Hello,

The math operation works perfectly.

frappe.ui.form.on("Sales Order", "meses", function(frm, cdt, cdn) {
	var d = locals[cdt][cdn];
	frappe.model.set_value(cdt, cdn, "valor_sin_intereses", Math.round(d.pagos / ((d.interes_anual / 100) / 12) * ( 1 - Math.pow(1 + ((d.interes_anual / 100) / 12),-d.meses))) + d.enganche);
	refresh_field("valor_sin_intereses");
});

The issue is that I repeated that script to refresh the result at “valor_sin_intereses” on changes…

frappe.ui.form.on("Sales Order", "interes_anual", function(frm, cdt, cdn) {...

frappe.ui.form.on("Sales Order", "pagos", function(frm, cdt, cdn) {...

frappe.ui.form.on("Sales Order", "enganche", function(frm, cdt, cdn) {...

But it actually only refresh the value in “valor_sin_intereses” when I make changes at “d.meses” field. Is there a best way to do this?

I think you can do this one, instead of getting the field using ````cdt and cdn. Especially if you are referring to the field name within the doctype, that is, not within the child table.

frappe.ui.form("Sales Order", "<fieldname>", function (frm) { ... } );

Also, use frm.set_value("valor_sin_intereses", value);

Thanks!