How to push data from child table to newly inserted doctype

Hi! Any one help me out of this one. :no_mouth:

From the one doctype Am having a button while clicking the button it will create a new doctype using frappe.db.insert() method. Now, Am fetching the value form one child table and send to the auto created child table, but I have given all this in Each so it’s creating every row in new doctype now i need all the rows in same doctype. I have attached a code and console log below , Kindly Help me out of this!

        frm.add_custom_button(__("Approve"), function(){
            frm.trigger('Approve');
            frm.set_value('workflow_state',"Approved By Sales Manager");
            frappe.msgprint("Approved By Sales Manager and send for block shipment.");
            frm.refresh_field('workflow_state');

            var a  = frm.doc.name;

           $.each(frm.doc.table_10,  function(i,  d) {



            globalThis.triger  = frappe.new_doc = ({

                "doctype" : "Redirecting",
                "link_1" : a,
    
                table_2 : [{
                   q_block_no : d.q_block_no
                },frm.refresh_field('table_2')] 
                
            });
            frappe.db.insert(triger),
            
            console.log(triger)
                
            });
            frm.save('Submit')


        }).addClass("btn-success").removeClass("btn-default");

Console log:

Output of insert doctype:
every rows are getting insert in a new doctype, I need all the rows in one doctype.

image

Thank you.

Any, one in forum can help me out of this :person_raising_hand:.

hello, do you have child table inside the Redirecting doctype and what is its name? anyway you dont need to use frappe.new_doc as you can just build your js object and use frappe.db.insert

example of how to insert a Doctype with its Child Table

frappe.db.insert({
    doctype: "Item Group",
    item_group_name: "My Cool Group3",
    is_group: 1,
    item_group_defaults: [
        {
            company: "My Company"
        }
    ]
    
})

you can try and tell us if that what you need

1 Like

Hi, @PyJumper
Each time I fill the value in one doctype called value and click the approve button it should create a new doctype inside a Redirecting and fetch the child table from the value and send to the Redirecting
value doctype child table is —> table_1
Redirecting doctype child table is —> table_2

So, that Am using the frappe.db.insert. Via, this the tables need to be get filled.
Could you help me in this case

Thank you.

Hi, @PyJumper
This is the table present in the value doctype this values need to be send once the approve button is clicked.

value doctype child table is table_1

Redirecting doctype child tavle is table_2

doctype type is getting created but only last row values are fetching not the entire table values are not getting fetched.

Kindly help me out of this.

Thank you.