Try ERPNext Buy Support Partners Foundation

Get data from different doctype

Hi Everyone,

I just create a new doctype name “Vehicle Info” which i add as a child table in the “Customer” doctype.

Also i added link field in Sales Order/Invoice. What i need is when i select a customer in sales order/invoice I just want to get the vehicles info which is related to the customer in the created link field.

Any help regarding this ? Please

i dont know if this is the correct way to do it, but what you need can be acheived by adding the below code in your sales invoice custom script

frappe.ui.form.on('Sales Invoice', {'cusomer': function(frm) { 
    frappe.call({
        method: "frappe.client.get",
        args: {
                doctype: "Customer",
                name: frm.doc.customer
        },
        callback: function (r){
                $.each(r.message.vehicle_info,  function(i,  d) { //replace vehicle_info with fieldname of your child table Vechicle Info
                        var new_child = cur_frm.add_child("child_table_fieldname_in_sales_invoice");
                        frappe.model.set_value(new_child.doctype, new_child.name, "coloumn_name_in_child_table_destination", r.message.vehicle_info[i].coloumn_name_in_child_table_source);
                        refresh_field("child_table_fieldname_in_sales_invoice")
                });
        }    
    });
}});

repeat the frappe.model.set_value for all the coloumns you have

Thanks, but i can’t understand “column_name_in_child_table_destination & column_name_in_child_table_source” because i’m new in ERPNext, Let me explain more with picture,

New created Doctype: “Vehicle Info”.

and this doctype is child table of customer which is perfectly connected

Now i created a fields in Sales Order. I’m attaching picture.

When i select the customer in sales order. I need v_vin data in above field which is related to customer.

Thankyousomuch Sir @neerajvkn

So you only need that single entry “v_vin” from child table in sales invoice?
will there be multiple vechiles for same customer?

When we create Sales Order/Invoice we need to add customer name. & what i want “v_vin” data in Customer Vehicle field which is related to the above enter customer name, Can you please help me ? @neerajvkn

let me make it more easy. “Customer with vehicle data”

Now. Check this two screenshot

In customer vehicle field there should be only 1 vehicle data because “Ghislain Gervais” only represent only 1 vehicles.

Thank you so much, I hope you’ll help me @neerajvkn