Custom Script for filtering

I have created a Custom Field ‘Party Type’ in Customer with ‘SELECT’ Type and with values Distributor,Reseller and Enduser options.I want to filter customer in Quotation according to value selected for ‘Party Type’.For that i have created below custom script .But itis not filtering.
cur_frm.cscript.custom_refresh = function(doc) {

   cur_frm.fields_dict['distributor'].get_query = function(doc) {             
   return{		
            filters:{'partytype': "Distributor"}
   }

}
}

It might be a silly question but as i can see.

your custom field lable is Party Type and name should be party_type.

And you are filtering with partytype

Have to changed the field name from party_type to partytype ?

Thanks Bhupesh for your reply.Field name for PartyType is partytype only.

This works for me.

cur_frm.set_query('distributor', function () {
    return {
        filters: {
            'partytype': 'Distributor'
        }
    }
});

An other silly query, you are saying that you want to filter Customers and have applied filter on distributor field name. Is that your intend or a typo?

Dear BhupeshGupta,
Thanks for your reply.‘distributor’ is the link field which is linked to Customer.But the below code also not filtering the Customers.All customers are showing.

cur_frm.set_query(‘distributor’, function () {
return {
filters: {
‘type’: ‘Distributor’
}
}
});

I think the custom fieldname in Customer master is “party_type”, not “type”. So, filter should be based on party_type.

cur_frm.set_query('distributor', function () {
    return {
        filters: {
            'party_type': 'Distributor'
        }
    }
});

Dear Nabin,
Thanks for your reply.It is working while commenting the line [“customer”,“customer”] in selling → sales_common.js.With out commenting this line , Is there any other possibility for doing this ?.Because we have only front end access for the PROD as it is on Frappe Cloud.

and commenting following code in hooks.

1 Like

Search engine gives highest priority to hooks.py, if there are any standard_queries mentioned for the document, it execute that one. And in frappecloud, users does not have access to hooks.py.

Thanks Nabin for your reply.