Filtering sales order items?

Hello community,
I am new in custom script development.
I need to perform “Sales Order Item” filtering in the sales order entry depending on the selected customer. For that purpose, I think it is possible to do that by means of using “Customer Item Codes” section in the “Item” form. When entering a sales order for a specific customer, only the products belonging to this customer who are registered in this table can be seen. I need a custom script to perform this filtering.
(The version I am using is v8.08)
Thanks in advance for your help


Refer the following link to apply filter on items


1 Like

I implement below code along with the py script:

frappe.ui.form.on(“Sales Order”, “customer”, function(frm, cdt, cdn) {
var p = frm.doc;

frm.set_query(“item_code”, “items”, function() {
return {
query: “erpnext.controllers.queries.cust_item_query”,
filters: {“customer_name”: p.customer}

It works fine except a little trouble. There are no any issues on querying. However when I insert consecutive sales orders, manually refreshing require for the correct querying by means of pressing “Reload” button after selecting a new customer from the combo box. Otherwise, the filtering stay unchanged based on the old customer selection, so it does not work correctly.

For that purpose, we did a few trials as shown below, but we did not get results.

frappe.ui.form.on(“Sales Order”, “refresh”, function(frm,cdt,cdn) {
var p = frm.doc;
var ilen = p.items || []
if(ilen > 0){
for( var i = 0; i < ilen.length; i++){

How can I configure automatic refreshing each time on new sales order entry?

Thanks in advance