I want to copy data from One Form Another via custom button

From custom doc called Machine Inspection to Create Sales Invoice here is my code

frappe.ui.form.on('Machine Inspection', {
    refresh: function(frm) {
        if (frm.doc.status == 'Completed'){
        frm.add_custom_button(__('Create Invoice'), () => {
            frappe.new_doc('Sales Invoice', {}, inv => {
                 inv.inspection_reference = frm.doc.name;
                 inv.customer = frm.doc.party_name;
            
            });
        }, __('Go to'));
        }
    }
    
});

While clicking Create Invoice then nothing is being carry forwarded to invoice.

Please guide I’m very new to even JS is also new.

Thank you

Please check the video, I have explained the same concept in the video.

Thank your your response. But before posting here I watched your full video after clicking button nothing is carry forward. I try to exact same line of codes.

Is your code have any version specific or it will work in all versions?

It’s worked in v14 and v15.

Please check the code: ERPNextWithNihantra/populate_data_one_doctype_another/populate_data_one_doctype_another.js at main · Nihantra-Patel/ERPNextWithNihantra · GitHub