Custom script to fetch total qty

Hi
Iam Using the below code to fetch total qty in stock entry

// code for calculate total and set on parent field.
total_qty = 0;
$.each(frm.doc.items || [], function(i, d) {
total_qty += flt(d.qty);
});
frm.set_value(“total_qty”, total_qty);
});

no success
can anybody tell me whats wrong
Regards
Hemanth

Used this code below
frappe.ui.form.on(‘Stock Entry’, {
refresh(frm) {
// your code here
total_qty = 0;
$.each(frm.doc.items || [], function(i, d) {
total_qty += flt(d.qty);
});
frm.set_value(“total_qty”, total_qty);
}
})
now there is no traceback error…but the value is not being displayed in the total_qty field

Regards
Hemanth

Try frappe.ui.form.on('Stock Entry Detail’ and instead of refresh as trigger use qty