Link field to selection of another

Hi

As you see in the picture under this text, i have a doctype wherein i can select a client (1) and a contact (2).
Each client has 1 or more contacts.
When i select the contact, the other fields (3-7) are filled in automatically.

I only have one problem with this: when i have selected a client, i see all the contacts.
How can i filter them to only show the contacts from the selected client?

Thanks.

Hello @Davy_Thoelen,

cur_frm.fields_dict["contact"].get_query = function (doc, cdt, cdn) {
            return {
                filters: {
                    'client': ['in', cur_frm.doc.client],
                }
            }
        } 

This might help!

Hi Shah

Do i need to add this to the field of the contact, or client?

Add it in the custom script for that particular custom doctype.

Ok, it looks like the script starts, but i get an error:
2019-09-19%2015_48_28-New%20Serviceorder%203

Davy I think you should list down what doctypes of ERPNext are being used in your case. Also, is this Client a link field of type Customer or is it some custom doctype you made ?

Exactly!
@Davy_Thoelen
Can you please list down the doctypes?
For the task you want to achieve, the client and contact should have some relationship to list down the contacts of the selected client.

Hi @root13F @Shah_Kalpit

Client is of doctype customer, and contact is of doctype address. These are linked by the field links in address.
Is it possible do use these doctypes for what i’m trying to do?

That is strange because there is a Contact doctype available, also for each Customer made there is a contact made automatically. I’m sure about this feature in version 11. Are you making contacts yourself ?