Duplicate a 'parent record' and duplicate all the 'child record' that are linked to the parent

Hi all,
I am new to the community and hope my English will allow you understand my question:

I am using airtable to do invoices. I have a table for the header (customer choice, project choice, etc.) and a table for the details of the invoie, ie all the lines. Each line is linked to the invoice by the invoice number. Sometimes my team do long and not easy invoices (in the construction industry), and on return the client just wants some modifications.

I am trying to do a script that duplicates the header and lines, so that I can keep my invoice history.

I can’t use the built in “Create records” action to create the duplicate “line” records, since the number of lines linked to any particular header can vary.

My problem is that when I duplicate the header (with an automation “create record” with trigger on the record I want to duplicate), the linked field is also duplicated but the lines themselves are not duplicated.
This way, If I change something on one line, it will be applicate on the 2 invoices (old and new). But I dont want that, I need to have the old version and the new version.

Already written some code but I don’t master airtable scripting (and it has to be in an automation)

Any help can be useful to me ! Thanks in advance !!