Show the full address in a custom field
Sales and purchase documents show the full text of the customer or supplier address. This page adds the same to any form: a link to an Address, and a field that shows the full formatted address.
Prerequisites
- The System Manager role.
Step 1: Add the fields
In Customize Form for your DocType, add two fields:
- A Link field, with Options
Address. For example, the labelSite Addressgives the field namecustom_site_address. - A Small Text field with Read Only selected, to show the address. For example, the label
Site Address Displaygives the field namecustom_site_address_display.
Select Update, and note both field names.
Step 2: Add the client script
Open the Client Script list, and select New.
In DocType, select your DocType.
Paste this script, and change the DocType name and the two field names:
jsfrappe.ui.form.on("Your DocType", { custom_site_address(frm) { if (!frm.doc.custom_site_address) { frm.set_value("custom_site_address_display", ""); return; } frappe.call({ method: "frappe.contacts.doctype.address.address.get_address_display", args: { address_dict: frm.doc.custom_site_address }, callback(r) { frm.set_value("custom_site_address_display", r.message || ""); }, }); }, });Select Enabled, and select Save.
Step 3: Test it
- Reload the form of your DocType.
- Select an address in Site Address.
Site Address Display shows the full address, formatted by the Address Template.