POS breaking for Sales Order on using Custom code


I am trying to populate the warehouse field in Sales Order Item using a custom code on sales order:

frappe.ui.form.on(“Sales Order Item”, “item_code”, function(frm, cdt, cdn) {
frappe.model.set_value(cdt, cdn, “warehouse”, “ware”);

This code is working well in normal mode. But when I am trying to use the POS mode the Item Name doesn’t get auto populated on selecting the item, thus the pricing and other fields also dont auto-populate.
Am I breaking something with the above code which is causing POS to work this way.
Please advice.