Not able to update the barcode when insert an item


I am trying, with this custom script, save the barcode of then item in the items table when I insert an item, but the field ‘barcode’ is always empty, however ‘qty’, for example, works well.

frappe.ui.form.on("Sales Invoice Item", "item_code", function(frm, cdt, cdn){
    var item = locals[cdt][cdn];{
    	'method': 'frappe.client.get_list',
    	'args': {
        		'doctype': 'Item Barcode',
    		'filters': { parent: item.item_code },
    		'fields': ['barcode'],
    		'parent': 'Item',
    	'callback': function(res){
    		if (typeof res.message !== 'undefined' && res.message.length > 0) {
			    var barcode = res.message[0].barcode;

			    cur_frm.doc.items[item.idx-1].qty = 2; //<--this works
			    cur_frm.doc.items[item.idx-1].barcode = barcode; //<-- this does not

I appreciate if anyone can help me with this.


1 Like