Item Barcode in Purchase Order

Hi All,

I m very new to ERPNext and I wanted to set up ERPNext for a Retail shop. I m running the software on the Cloud. However, I m stuck on creating Item barcode in PO.

I have items having multiple barcode (Based on UOM). And I wanted to print the barcode (just the barcode number is also fine) in the purchase order so that during purchase receipt, my employee can just scan the barcode and create labels during entry.

I can see Item Barcode is a child table under Item and Purchase Item is a child table in Purchase Order. So, I tried to fetch the Item Barcode entry for a selected Item(as fetched from Material Request) and compare if the UOM is same and then print the barcode using the following client script (as I could find similar in the internet). However. I m not sure what I m doing wrong. Can please anyone help?

frappe.ui.form.on("Purchase Order", "refresh", function(frm) {
frappe.model.with_doc("Item", frm.doc.trigger, function() {
    var tabletransfer= frappe.model.get_doc("Item", frm.doc.Trigger)
    $.each(tabletransfer.barcodes, function(index, row){
        d = frm.get_selected("items");
        if (d.qty == row.posa_uom)
        {
        d.item_barcode = row.barcode;
        }
        cur_frm.refresh_field("items");
    });
})

});