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:

  1. A Link field, with Options Address. For example, the label Site Address gives the field name custom_site_address.
  2. A Small Text field with Read Only selected, to show the address. For example, the label Site Address Display gives the field name custom_site_address_display.

Select Update, and note both field names.

Step 2: Add the client script ​

  1. Open the Client Script list, and select New.

  2. In DocType, select your DocType.

  3. Paste this script, and change the DocType name and the two field names:

    js
    frappe.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 || "");
    			},
    		});
    	},
    });
  4. Select Enabled, and select Save.

Step 3: Test it ​

  1. Reload the form of your DocType.
  2. Select an address in Site Address.

Site Address Display shows the full address, formatted by the Address Template.