How to fetch value from one doctype to another doctype

i want to fetch values from one doctype for filling another doctype fields…the two doctypes are not linked to each other… but have one common column named prospect_id in it… can someone know how to get that done…the code below show error like " pymysql.err.ProgrammingError: (‘DocType’, ‘Doctype’) ".

import frappe
from frappe.model.document import Document

class Policy(Document):

        def copy(motor,sub_model,make,model,reg_number,policy,target_fields,prospect_id):
                motors = frappe.get_all(motor)

                for moto in motors:
                        source_doc = frappe.get_doc(motor,
                        source_value = source_doc.get(sub_model,make,model,reg_number)

                        target_doc = frappe.get_doc(policy,{prospect_id:source_value})

                        if target_doc:
                                for target_field in target_fields:


Hi @BalaV,

Please apply the client script for it.
Here, we share the syntax, so please set your doctype and field according.

frappe.ui.form.on('SecondDocType', {
    refresh: function(frm) {
        // Fetch values from FirstDocType based on prospect_id
        frappe.db.get_value('FirstDocType', {'prospect_id': frm.doc.prospect_id}, 'field_name', function(value) {
            // Update field in SecondDocType with the fetched value
            frm.set_value('field_name', value.field_name);
            // Repeat the above line for other fields you want to populate

I hope this helps.
Thank You!


Thank You, @NCP
The code you shared works…! thanks for helping me in a short time.

frappe.db.get_value('FirstDocType', {'prospect_id': frm.doc.prospect_id}, '*', function(value) {

when i give multiple value in field name it gives the first field name value ,so i added asterisk instead.
thank you :grinning: