Fetch the table from customer into the quotation by custom script

Hello,

I have requirement in which customer is buying frequent item so by making
quotation for them those main items should be added into that separate table.
so i have created new doctype named “Customer Items” in customer and name of the table is “customer_item” and added some values like equipment , pressure etc . and also created new doctype “quotation specific customer items” and used table named “customer_item” with same attribute in quotation.
so if the particular customer is selected then that table should be fetched.
I am using following script please suggest the changes
it’s not working

frappe.ui.form.on(“Quotation”,“customer”, function(frm, cdt, cdn) {

frappe.call({
    method: "frappe.client.get_list",
    args: {
        doctype: "Customer Items",
               fields: ["equipment", "serial_no", "manuf_year", "pressure"]
    },
    callback: function(r) {

        var items = [];
        frm.clear_table("customer_item");
        for (var i = 0; i < r.message.length; i++)
            
        {
            var d = frm.add_child("customer_item");
            for (var key in r.message[i]) {
                if (r.message[i].hasOwnProperty(key)) {
                    frappe.model.set_value(d.doctype, d.name, key, r.message[i][key]);
                }
            }
               console.log(r.message)      
              if (!d.qty) d.qty = 1;
        }
        frm.refresh_field("customer_item");
    }
})

})

Hi @surajkumar,
I’ve not replicated and tested your code…but from looking at it, the “console.log” statement is placed wrongly, please delete that line and place in the curly bracket and test you code again.

Hello @surajkumar

I suggest something for you will help you to resolve your problem:
Instead of saying that it is not working, it is better to determine where exactly your code stuck and this can be by dividing your code into parts (comment part and leave part active) and step by step, until you reach for the sentence this is fail at it.
Also check browser console if you see any error (java error).

Regards
Bilal

thank you @bghayad
yes I did it there is problem in callback function.
script is working for fetching the table of customer but that values are not reflected into quotation table.callback function has error. please suggest the changes

thank you @bomsy.
I have placed the function in curly braces but still not working there is problem in callback function. please suggest the changes

hello,
@bomsy @bghayad
I have tried following script and its working but the only problem is now its fetching the all rows of the table but there are different data for different customer so when I select the customer then the the rows of data of that particular selected customer should be appear. I think there is problem in filters please suggest the suitable changes

frappe.ui.form.on(“Quotation”,“customer”, function(frm, cdt, cdn) {

frappe.call({
    method: "frappe.client.get_list",
    args: {
        doctype: "Customer Items",
filters: {
            "Customer": frm.doc.customer,
          },
               fields: ["equipment", "serial_no", "manuf_year", "pressure"]
    },
  
    callback: function(r) {
            var items = [];
            frm.clear_table("customer_speacial");
            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, d.name, key, r.message[i][key]);
		    }
	}

                if(!d.qty) d.qty = 1;
            }
            frm.refresh_field("customer_speacial");
        }
})

})

with above script
“OperationalError: (1054, “Unknown column ‘tabCustomer Items.customer’ in ‘where clause’”)” this error occures

Why you placed the filter inside the frappe.call and did not place at onload or setup event?
By the way: can you please pictures of the screen about what you are doing to understand what do you need exactly?
Regards
Bilal

thank you @bghayad

I am quite new for this.
there is one table in customer for which new custom doctype is used named “Customer Items” and this table is to be fetch in quotation where I have created new table named"Customer Speacial ". by using above script that whole table is being fetched. but I want that whenever particular customer is selected the table values corresponding to that customer only should be added into the table which is created in quotation. by using current script without selecting customer the table value of all customer is added as shown in first screenshot whereas if I am selecting any xyz customer then the rows of values of that customer should be added into table

please suggest the changes in the above code

Hello @surajkumar

What if you did upgrade for ERPNext? All your custom code will be erased. Are you aware for this? I hope to hear answer from you about this point.

I suggest to pass the customer as argument for the frappe.call and to use it in the sql query.

Regards
Bilal

thank you
@bghayad

I have back up of all the customization. I will take care of it, for now I don’t want to upgrade.
I made the changes in code like I have passed customer argument in frappe.call but it is not working.
please rewrite your suggestion here if possible