Unable to fetch Data

Dear Community,
When Estimation is created and create quotation via estimation.
If the Estimation is Customer the Party (Dynamic Link) auto fetch the customer name and other details but if the estimation is Lead it only change the Party label as Lead but not fetch.

Estimation:

Quotation:

Estimation Doctype:

Quotation Doctype:

It fetch other details but not lead, but it works on customer.

Even i tried code,

frappe.ui.form.on('Quotation', {
    before_save: function(frm) {
        if (frm.doc.estimation) {
            frappe.db.get_doc('Estimation', frm.doc.estimation)
                .then(doc => {
                    // Set quotation_to and party_name based on estimation_for
                    if (doc.estimation_for === 'Customer' && doc.customer) {
                        frm.set_value('quotation_to', 'Customer');
                        frm.set_value('party_name', doc.customer);
                    } else if (doc.estimation_for === 'Lead' && doc.lead) {
                        frm.set_value('quotation_to', 'Lead');
                        frm.set_value('party_name', doc.lead);
                        
                        // Fetch Lead details and assign to party_name
                        frappe.db.get_value('Lead', doc.lead, 'lead_name', (r) => {
                            if (r && r.lead_name) {
                                frm.set_value('party_name', r.lead_name);
                            }
                        });
                    } else {
                        console.log('No valid customer or lead found in the estimation document.');
                    }
                })
                .catch(error => {
                    console.error('Error fetching estimation document:', error);
                });
        }
    }
});

Can you help how to solve this issue.

Thanks in Advance

Hello @Rizwaan
From my understanding, instead of using “Lead” and “Customer” as separate links, you should follow the same approach used in the “Quotation” doctype. Add a dynamic link field named “Party,” where the key must be party_name. In this case, you won’t need to write custom JavaScript to fetch the data. The default mapper will automatically retrieve the correct value because your doctype field party_name will match the party_name field in the “Quotation” doctype.

Estimation Doctype is Customized doctype even i make same field name it not fetch quotation to and party