Want to add items in custom child table through scan barcode field ( like in sales order, purchase invoice)

Hello there.
i hope you all are fine.

I added a child table name (items) in doctype Donation(in Non_profit module)
and added a field Scan barcode above the child table

and added custom script in donation doctype

    scan_barcode: function(frm, cdt, cdn){
	if (frm.doc.scan_barcode){
		frappe.db.get_value('Item', {item_code: frm.doc.scan_barcode}, 'item_code', (r) => {			
			if(r !==undefined){					
				var row_count=frm.grids[0].grid.grid_rows.length;
				var cur_grid= frm.grids[0].grid
				var find_exist_row = "no";
				for (var i = 0; i < row_count; i++) {
					if (cur_grid.grid_rows[i].doc.item_code ===undefined) { 							
						find_exist_row = "empty";
						break;
					}						
					else if (cur_grid.grid_rows[i].doc.item_code ===r.item_code) { 
						find_exist_row = "yes";						
						break;
					}						
				}
				if (find_exist_row === "no"){
					var new_row= cur_grid.add_new_row()
					if (new_row !==undefined){
						frappe.model.set_value(cur_grid.doctype, new_row.name, "item_code", r.item_code);
					};								
				}
				else if (find_exist_row === "empty"){
					frappe.model.set_value(cur_grid.doctype, cur_grid.grid_rows[i].doc.name, "item_code", r.item_code);
				}
				else{
					if (cur_grid.grid_rows[i].doc.qty !=undefined){
						frappe.model.set_value(cur_grid.doctype, cur_grid.grid_rows[i].doc.name, "qty", cur_grid.grid_rows[i].doc.qty + 1);
					}
				}					
			}
		});					
		frm.set_value('scan_barcode','');
		console.log(set_value)	
	}
return false;
},

but when i enter barcode in scan barcode i get the message
image
and items not adding to the child table.
I used this link [New Feature Proposal]Barcode scan to create/update records in child table, useful for stock movement and orders

your help will highly be appreciated
Thank you