I want to make a button with get item from purchase order with a New doctype as pi_entry

I have make a new doctype as pi_entry, now i want to make a button get_item_from purchase order and fetch the purchase order item_table data to pi_entry.

Please help me to do this

@Arafat_Mehedi you can open any other doctype that has this same feature in github . and follow the codes

You can achieve this using Client Script.

I have developed this to get a specific Supplier’s Item that has been purchased in Past.

frappe.ui.form.on("Old Purchase", "refresh", function (frm) {
   
    frm.add_custom_button("Get Invoice Data", () => {
             
    	frappe.call({
            method: 'frappe.client.get_list',
            args: {
            doctype: 'Purchase Invoice',
            fields:["name","posting_date"],
            filters: [
                     ['supplier', '=', frm.doc.supplier_name]
                ]
            },
         async:false,
        callback: function(r) {  
            var pi = r.message;
            pi.forEach(function(d) {   
                
                frappe.call({
                        method: 'frappe.client.get_list',
                        args: {
                            parent:"Purchase Invoice",
                            doctype: 'Purchase Invoice Item',
                            fields:["item_name","rate","qty","amount"],
                            filters: [
                                ['parent', '=', d.name]   
                            ]
                        },
                        async:false,
                    callback: function(res) {
                        if(res.message !== "item not in table"){
                        
                        var ds = res.message;
                        
                        ds.forEach(p => { 
                            frm.add_child('historical_purchase', {
                                invoice_date: d.posting_date,
                                invoice_no: d.name,
                                item_name:p.item_name,
                                qty:p.qty,
                                rate:p.rate,
                                amount:p.amount
                            });
                        });
                    }}
                });
 });
       frm.refresh_field("historical_purchase");
   
})});