- Create a Link field to Address DocType primary_address
- Create a HTML field type and use Name : address_html (The field name has to be address_html or it will not work as intended.)
- Check if file is not saved then use in JS:
if(!frm.doc.__islocal) {
frappe.contacts.render_address_and_contact(frm);
} else {
frappe.contacts.clear_address_and_contact(frm);
}
- To filter address list by selected user, use in JS:
frm.set_query('primary_address', function(doc) {
return {
filters: {
'link_doctype': 'DocType',
'link_name': doc.name
}
}
})
- In .py file use:
def onload(self):
"""Load address and contacts in `__onload`"""
load_address_and_contact(self)
- To delete address on deleting entry:
def on_trash(self):
delete_contact_and_address("Member", self.name)
- Imports required:
from frappe.contacts.address_and_contact import (
delete_contact_and_address,
load_address_and_contact,
)