Validate warehouse in Sales Invoice Item

Hullo Members,
ERPNEXT Version 6.27
he problem is we have setup a POS profile and set default warehouse for every user, so that each users warehouse in the sales invoice will be different, however on some occasions the warehouse will differ from the default warehouse for the user.
Our solution:
To validate the warehouse in the sales invoice item(Child Doctype) with a warehouse in the Sales Invoice(Parent Doctype). I have created a custom warehouse field in the Sales Invoice to use for validation.

I am trying to achieve the validation with a custom script in Sales Invoice as shown below but its not working. Please help why is the code not working? any suggestions or alternative approached are welcome.

frappe.ui.form.on(“Sales Invoice Item”, “validate”, function(frm, cdt, cdn) {
$.each(frm.doc.items || [], function(i, d) {
if(frm.doc.warehoused != d.warehouse) {
msgprint(“Please check Items table and enter correct Warehouse”);
validated = false;
}
}
});

On too old version. Will highly suggest upgrading, so that others can assist you with the queries. Also, not safe to stay on so old version.