How can I make a "runtime" calculation?

Try something like this.

frappe.ui.form.on('<< Child Table DocType Name >>', {
	<< Field name on child table #1 >>: function(frm, cdt, cdn) {
		let gridRow = frm.open_grid_row();
		if (!gridRow) {
			gridRow = frm.get_field('<< Field name of child table on main form >>').grid.get_row(cdn);
		}
		calAmount(gridRow);
	},
	<< Field name on child table #2 >>: function(frm, cdt, cdn) {
		let gridRow = frm.open_grid_row();
		if (!gridRow) {
			gridRow = frm.get_field('<< Field name of child table on main form >>').grid.get_row(cdn);
		}
		calAmount(gridRow);
	},
});


function calAmount(gridRow) {
	let qty = gridRow.on_grid_fields_dict.<< Field name on child table #1 >>.value;
	let rate = gridRow.on_grid_fields_dict.<< Field name on child table #2 >>.value;
	let amount = qty * rate;
	frappe.model.set_value(
		gridRow.doc.doctype,
		gridRow.doc.name,
		'<< Field name on child table #3 >>',
		amount
		);
}
3 Likes