Try ERPNext Buy Support Partners Foundation Foundation Members

Dynamic Link in Addresses

Hi all,

I have built a custom app with a new doctype named ‘Patient’.
I want to be able to create an address directly from that patient and to linke the address automatically at the creation, the same way it is linked to a customer or lead for example:

Example: Client address creation

At the creation, the reference link is automatically created:

When trying to do it in the custom app, the reference links are not populated.
It seems the dynamic link doesn’t work.
Here is my code:

frappe.provide("customApp");

customApp.PatientController = frappe.ui.form.Controller.extend({
    refresh: function() {
        var me = this;
        frappe.dynamic_link = {doc: me.frm.doc, fieldname: 'name', doctype: 'Patient'};

        if(me.frm.doc.__islocal){
            hide_field(['address_html']);
            frappe.geo.clear_address_and_contact(me.frm);
        }
        else {
            unhide_field(['address_html']);
            frappe.geo.render_address_and_contact(me.frm);
            erpnext.utils.set_party_dashboard_indicators(me.frm);
        }

    }
});

$.extend(this.frm.cscript, new customApp.PatientController({frm: this.frm}));

Since I have also a mapping with a customer, I tried to add the following dynamic link but it is not working either:

frappe.dynamic_link = {doc: me.frm.doc, fieldname: ‘customer’, doctype: ‘Customer’};

If anyone has any clue on how this could work and if I am missing something in the way the data is passed to the address, that would be great.

Thank you!

Your code seems correct. As long as you are creating a new Address from the Patient form, it should work. Maybe check your JS for unrelated errors.

1 Like

Thank you for your answer Rushabh.

I don’t have any error message in the JS console, that is strange indeed…

I will continue to investigate and let you know if I find the root cause.

I was hoping someone from the community had already faced this issue and solved it.

Hi @rmehta,

For information, the issue was related to the naming series.

Since the series was PAT/ and the address.js slices the route based on the “/”, it was unable to fetch the document name.

Difficulty is always hidden in the details… :wink:

Thanks for your help anyway!

2 Likes