Customer name in child table field


I have created new doctype named “Customer Items” and added table in “Customer”
which has following fields
I want the customer name fetched automatically in table data field"customer_full_name" whenever new row is added.

table name is “Customer Items”

I have written following script in “customer”
suggest the changes

frappe.ui.form.on("Customer", "refresh", function(frm, cdt, cdn){{
        "method": "frappe.client.get_value",
         args: {
            doctype: "Customer",
   	        fieldname: "customer_name"		   			
         callback: function (data) {									 
                cur_frm.set_value("customer_full_name", data.message.customer_name);


thank you

why don’t you make Customer full name field in your new DocType as ‘LINK’ field and attach it to customer name in the option window.

thank You @FinForce
for reply

even when other fields of the table are different but customer full name field should be same as the customer name in which this table is created .

link field will give us drop down so every time i have to select the same customer name.
where as i want set it default and whenever new row is added the customer full name field should be same as customer name

ok, I understand it now. I don’t know how to do it.

But, what is your UseCase for Customer Item under Customer docType? And what you plan to solve a problem by doing this?

I want that table in quotation
for that perticular customer
lets consider if quotation for xyz customer is created then the table of that customer should be fetched in quotation
I have also created same table in quotation by creating new doctype.
bellow script is working but i have to place name of customer in customer doctype for each item
otherwise it will fetch all the rows of different different customer into quotation of that perticular customer.

  frappe.ui.form.on("Quotation","customer", function(frm, cdt, cdn) {{
    method: "frappe.client.get_list",
    args: {
        doctype: "Customer Items",
              "customer_name" : frm.doc.customer

               fields: ["equipment", "serial_no", "manuf_year", "pressure"]
    callback: function(r) {
            var items = [];
            for(var i=0; i< r.message.length; i++) {
                var d = frm.add_child("customer_speacial");
	for (var key in r.message[i]) {
		    if (r.message[i].hasOwnProperty(key)) {           
		frappe.model.set_value(d.doctype,, key, r.message[i][key]);

                if(!d.qty) d.qty = 1;



hi , you can try this :slight_smile:

i am writing this after bit of exploration

var row=locals[cdt][cdn]

actually every time any row gets added a particular method is triggered like above (adding screen shot )

fabric_inspection_fabrics → this is my child table and “_add” if i suffix it and write method in a child table that method will be triggerd after adding row automatically you can do your hack with it like i did.

cheers :wink:

thank you @AkshayJadhao

I am new for scripting could you please elaborate
with following details.

doctype: Customer
field to be fetch : customer_name

table name: customer_item (in customer)
doctype: Customer Items
field in which name to be fetched: customer_full_name(type=data)

customer itewm table is in customer doctype which has column named customer_full_name.
so in this field the customer_name should be fetched as shown in above screenshot.

I have tried the code you have suggested as follows.

add_new_row: functionidx, callback, show) {
 if(this.is_editable()) {
 if(this.frm) {
var d = frappe.model.add_child(this.frm.doc, this.df.options,this.df.customer_name, idx);
 d.__unedited = true;
this.frm.script_manager.trigger(this.df.customer_full_name + "_add", d.customer,;  
   } else {{name: "batch" + (, idx:});

hi try this

    var row=locals[cdt][cdn]


thanks again @AkshayJadhao

I have tried the script, not working .
I want to pick the customer name and put it in the table it will same for all the items.
table is in “Customer Items” custom doctype, I have used it in customer form same as “Quotation Item” in “Quotation”.

thank you guys

I got solution.

   frappe.ui.form.on("Customer Items", {
customer_item_add: function(frm) {
      var last_id = frm.doc.customer_item.length - 1;
frappe.model.set_value(frm.doc.customer_item[last_id].doctype, frm.doc.customer_item[last_id].name, "customer_name", frm.doc.customer_name);