Custom field in "address_html" and "contact_html"

How to custom field “Test 1” which is in the “Doctype Address” appears in the “Address and Contacts” that is the “Doctype Supplier”?

@Gleisson03, do you need create a custom script to override the actual html template that you can see here: https://github.com/frappe/erpnext/blob/6239923340d83465c34e12cddb852579576e08c5/erpnext/public/js/templates/address_list.html

@rmehta, these case can use the Address Template instead of this fixed template?

1 Like

@Gleisson03, do you need create a custom script to override the actual html template that you can see here: https://github.com/frappe/erpnext/blob/6239923340d83465c34e12cddb852579576e08c5/erpnext/public/js/templates/address_list.html

@rmehta, these case can use the Address Template instead of this fixed template?

Even if you explain that way, unfortunately I have no knowledge to know exactly what to do, explain to me a little more please?
@max_morais_dmm → I would like to thank you for helping me whenever I needed until now! Thanks ! :smiley:

Did you check this? https://frappe.github.io/erpnext/user/manual/en/setting-up/print/address-template.html

1 Like

Thanks for the replies. Now I could add my custom fields in the “address_html”.

But I did not find where I edit the field “contact_html”…

Thanks in advance.

Did you get an idea of how to edit the “contact_html” field? I have the same question and I can’t find where to handle this field. I’ve managed to change the Address_html without any problems, but I need to know what file to edit, as I presume it is somewhere in the code and not in ERPNext.

That’s right… it’s in the code :wink:

Any idea in which file?

@pedro_vde,

Here is such an example:

or another one here:
https://github.com/frappe/erpnext/blob/develop/erpnext/non_profit/doctype/volunteer/volunteer.js

and the 2 js functions, you’ll need:

else {
			unhide_field(['address_html','contact_html']);
			frappe.contacts.render_address_and_contact(frm);
}

Thanks for the hints f_deryckel. As I’m completely new to frappe/ERPNext and setting my first steps here…

I’ve added the field that I want to add in the HTML contact display. In /buying/doctype/supplier/supplier.js I’ve added a line (117) from:

supplier_primary_contact: function(frm) {
if (!frm.doc.supplier_primary_contact) {
frm.set_value(“mobile_no”, “”);
frm.set_value(“email_id”, “”);

to:

supplier_primary_contact: function(frm) {
if (!frm.doc.supplier_primary_contact) {
frm.set_value(“title_or_position”, “”);
frm.set_value(“mobile_no”, “”);
frm.set_value(“email_id”, “”);

where “title_or_position” is a custom field that I’ve added in the contact DocType.

Unfortunately, the custom field does not show up. I’ve restarted the bench, but I’m probably missing something.

how you edit the address_html?

how u manage the address_html …i need to add custom field value in the html…can you help me?

sorry, I can’t help you… I was not able to figure it out on my own.

Hi I was able to resolve.

JS File:

frappe.ui.form.on('Sample', {
    refresh: function(frm) {
        frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Sample'};
        frm.toggle_display(['address_html','contact_html'], !frm.doc.__islocal);
        if(!frm.doc.__islocal) {
            frappe.contacts.render_address_and_contact(frm);
        } else {
            frappe.contacts.clear_address_and_contact(frm);
        }   
    }
});

PY File:

from __future__ import unicode_literals
from frappe.model.document import Document
import frappe
from frappe import _
from frappe.contacts.address_and_contact import (
    delete_contact_and_address,
    load_address_and_contact,
)

class Sample(Document):
	def onload(self):
		“”“Load address and contacts in __onload“””
		load_address_and_contact(self)

I hope this will help :slight_smile: