Client script: Event trigger after Item fetch

Hi guys,

So i have this problem with client script. Normally when I create custom_qty in Purchase Order Item it works.
But if the qty is changed because of a new fetch of item_code, the event is not triggered, therefore custom_qty function will not be executed.

cur_frm.cscript.custom_item_code = function(doc, cdt, cdn) {
    console.log('custom item_code');
    // locals [cdt][cdn].qty is not updated here 
cur_frm.cscript.custom_qty = function(doc, cdt, cdn) {
    console.log('custom qty');

Is there any different method that I can hook on too ? Even if I use custom_item_code, the qty return there is still the old one not the one after fetched

Thank you

okay with a little more digging to the code, i realize it’s this code in public/js/transactions.js

item_code: function(doc, cdt, cdn) {
	var me = this;
	var item = frappe.get_doc(cdt, cdn);
	if(item.item_code || item.barcode || item.serial_no) {
		if(!this.validate_company_and_party()) {
			cur_frm.fields_dict[me.frm.cscript.fname].grid.grid_rows[item.idx - 1].remove();
		} else {
			console.log('qty2', item.qty);
				method: "erpnext.stock.get_item_details.get_item_details",
				child: item,
				args: {
					args: {
						item_code: item.item_code,
						barcode: item.barcode,
						serial_no: item.serial_no,
						warehouse: item.warehouse,
						parenttype: me.frm.doc.doctype,
						customer: me.frm.doc.customer,
						supplier: me.frm.doc.supplier,
						currency: me.frm.doc.currency,
						conversion_rate: me.frm.doc.conversion_rate,
						price_list: me.frm.doc.selling_price_list ||
						price_list_currency: me.frm.doc.price_list_currency,
						plc_conversion_rate: me.frm.doc.plc_conversion_rate,
						order_type: me.frm.doc.order_type,
						is_pos: cint(me.frm.doc.is_pos),
						is_subcontracted: me.frm.doc.is_subcontracted,
						transaction_date: me.frm.doc.transaction_date,
						ignore_pricing_rule: me.frm.doc.ignore_pricing_rule,
						doctype: item.doctype,
						project_name: item.project_name || me.frm.doc.project_name

				callback: function(r) {
					console.log('qty3', item.qty);
					if(!r.exc) {
						me.frm.script_manager.trigger("price_list_rate", cdt, cdn);

It’s only inside the callback where qty has changed. So we can use custom_price_list_rate

1 Like