Field value which changes depending on value of other fields

@nabinhait @anand
I have written below custom script to a field which changes value depending on other fields. But it does not work. Kindly help…

Script Type: Client

Script:

cur_frm.cscript.qty = function(doc, cdt, cdn) {

if (doc.qty && doc.unit_cost) {
doc.total_cost = flt(doc.qty)*flt(doc.unit_cost);
refresh_field(‘total_cost’);
}
}
cur_frm.cscript.unit_cost = cur_frm.cscript.qty;

Try the following (assuming all the fields are in item table):

cur_frm.cscript.qty = function(doc, cdt, cdn) {
	var d = locals[cdt][cdn];
	if (d.qty && d.unit_cost) {
		d.total_cost = flt(d.qty)*flt(d.unit_cost);
		refresh_field('total_cost', cdn, 'items');
	}
}
cur_frm.cscript.unit_cost = cur_frm.cscript.qty;

@nabinhait

will it work for child table also?

because i’m using it for child table.

Yes, it is for child table only. In which child table, you have added those fields?

Thanks…its working

These fields I have added in child table “Working Sheet”, to do required calculations before raising Quotations.

Currently we are maintaining this in MS Excel, & would like to implement in erpnext.

As it is for “Working Sheet” child table, you have to specify correct fieldname for the child tables instead of “items”.