Without a translation, I can't read the text in your screen shots and thus cannot identify what each item represents.
The script looks like a very common method for taking data in one table and using it to make a new record in another table. Normally, a estimate has a set of related line items and I do not see any scripting that would copy over the line items data--that would normally require using a loop to loop through a set of records.
But why copy estimates to another table to make them into invoices? Why not take the estimate record and relabel it as an invoice?
This doesn't fit the needs of every business, but if it works for you, it's far simpler to change the value of a single text field from "estimate" to "invoice" than it is to copy all of this data to another table.
thank you very for the replyYour relabeling solution looks indeed way more simple, but in this scenario, would iT be possible to keep the original estimate? Because I would really like to keep these on file.
Your original estimate would also be your invoice. If you data does not change when it becomes the invoice, you would still have this data. If invoices may be modified to be different from the originating estimate, you'll need to preserve a copy of this data, but you still would not need to move the data into a different table. You could duplicate your original estimate and set of line items in the same table(s) and not have to export the data to a different table like you have attempted to do.
See this thread for a sample script: Duplicating Bill Of Materials (duplicating portal line items)