Use table for filtering link field

I have custom doctype “BOM Notes” which is defined as table. Table has Item code field which is linked with Item doctype.
While creating the BOM, user can fill “BOM Notes” table, but I want filter Item Code field so that only Items from BOM Item table can be used.
Code I made is below. I have problem with fetching item codes from BOM Items table.
Not sure how I should do it. Thanks!

var BOM_Item;

frappe.ui.form.on('BOM', {
	setup: function(frm) {
		frm.set_query("item_code", "per_item_notes", function() {
			return {
				filters: [
					["Item", "item_code", "in", BOM_Item["item_code"]]

frappe.ui.form.on('BOM Item', {
    item_code: function(frm, cdt, cdn) {
        BOM_Item = locals[cdt];