Overriding Link Query By Custom Script

i have Created an item.js file under js/overrides and created a query for the child table Preferred Zones where i can only select warehouses with designation zone (i add it to warehouse doctype designation its a select and it can be zone)

I’ve encountered an issue with the query portion. I’ve created ‘item.js’ under overrides and here’s the query I’ve implemented:

frappe.ui.form.on(‘Item’, {
refresh: function(frm) {
frm.set_query(‘custom_zones’, ‘Preferred Zones’, function() {
return {
filters: {
‘custom_designation’: ‘Zone’
}
};
});
// just a message
frappe.msgprint(“Item form script executed successfully!”);
}
});

However, I didn’t get any results when I made a selection. I’m unsure why this is happening I believe I’ve added it to the hooks. Here’s my ‘hooks.py’ part:

app_include_js = [
“/assets/wms/js/overrides/warehouse.js”,
“/assets/wms/js/overrides/item.js”
]
doctype_js = {
“Item”: “public/js/overrides/item.js”
}
i get this erroes too in the console "function refresh(frm) and Uncaught (in promise) TypeError: this.fields_dict[opt1] is undefined

Hi @lmahdy1,

Override javascript function:

Overriding Link Query By Custom Script:
https://frappeframework.com/docs/user/en/guides/app-development/overriding-link-query-by-custom-script

Few reference (Override javascript function):

Also, check the field name according to Overriding Link Query By Custom Script

Thank You!

1 Like