Filter a Dynamic Link type field

Hello everyone, I have a problem in the Payment Entry I have a link field “party_type” in which you can only choose between Supplier and Customer, and according to that the options appear in another field that is dynamic link “party” what I am trying is to filter the field “party” according to the company, whether they are Supplier or Customer and I do not know why the filters I use only serve me when it is Supplier, in the case that it is Customer they do not serve.

Does anyone know how to solve this problem?

In case you already have data in Customer master then possibly you can check your permissions.

Hi, I do not think it’s because of the permissions since the information is shown, but the filter in the field does not work

Hi all,
I have the same issue where I try to restrict party to only customers/suppliers that are not disabled. However, the following query is simply not used to filter (i.e. overruled by other filters, I guess):

frappe.ui.form.on('Payment Entry', {
    refresh(frm) {
	// your code here
	if (frm.doc.party_type === "Customer") {
	    cur_frm.fields_dict.party.get_query = function(doc) {
             return {
                 filters: {
                     "disabled": 0
                 }
             };
        };
    }
}

}

Does that code execute? Try it with a console.log

1 Like

Thanks for the hint, @Nahuel_Nso, it did not :wink:

Now it does:

frappe.ui.form.on('Payment Entry', {
    party_type(frm) {
        if (frm.doc.party_type === "Customer") {
            cur_frm.fields_dict.party.get_query = function(doc) {
                 return {
                     filters: {
                         "disabled": 0
                     }
                 };
            };
            console.log("filtered");
        }  
    },
}

And actually works. Thank you!

2 Likes

Thanks for the working code :boom: