Limit Addresses based on Filtered Address type

I see that the Address doctype has a field address_type which is a Select list which includes { Shipping, Office, Personal, etc… }.

I would like to create a custom field in another doctype which is linked to Address. However, when entering the Address… I ONLY want the user to be able to select addresses where address_type == “Shipping”.

Can this be done?

Thank you in advance.

Hi @rich,

Just check the following code, here instead of address you need to give the name of address filed.

frm.set_query('address', () => {
    return {
         filters: {
             address_type == “Shipping”
1 Like

Thanks SherinKR… Can I achieve this same functionality by using the Form editor, and editing the custom field? Specifically, can I use either the “Display Depends On” or the “Mandatory Depends On” to achieve this?

I was hoping to be able to do this through configuration, rather than modifying source code.

Yes, you can add one Client Script for the Doctype. It will fulfill the requirement.

1 Like