Copying an invoice from Posted Sales Invoices to Sales Invoices (Unposted) in an Al Extension

I’ve written an AL Extension that clones / copies an invoice from Posted Sales Invoices to Sales Invoices (Unposted) using Record.TransferFields. At the same time it edits a description in a Comment line within the invoice. This works fine, but when I try to post the invoice in question, it reports an error stating that fields ‘Qty. To Invoice’ & ‘Qty.To Ship’ should contain a value that appears to be the same as field Quantity. (i.e. If Quantity = 4, then it complains that the aforementioned Qty fields are not also set to 4.

On investigation, fields ‘Qty. To Invoice’ & ‘Qty.To Ship’ do not exist in the posted table (Sales Invoice Line) but do in the unposted table (Sales Line) . This, I guess, explains why Record.TransferFields doesn’t put a value in these 2 fields because there’s no source.

So, I wrote an extra procedure to pass through the lines and copy the value in Quantity to ‘Qty. To Invoice’ & ‘Qty.To Ship’. This changed the error to ‘You cannot post these lines because you have not entered a quantity on one or more of the lines’.

There is a comment line that does not contain a quantity value because it is a comment (stating the obvious). The whole purpose of the extension is to copy a posted invoice to unposted and change the comment.

Question 1:
Did I do the right thing in copying the value(s) from Quantity to ‘Qty. To Invoice’ & ‘Qty.To Ship’?

Question 2:
Is it valid for an invoice to contain a Comment line having no Quantity?

Any other help would be welcome.

When you have already copy document function out of the box NAV not sure why you are writing a process. You will create a new Invoice and then use the copy document function to copy from posted invoice that will copy the header and lines from the posted invoice and then you can change what ever information you need on the invoice.

There is standard functionality with Copy Document that already copies a Posted sales invoice into an unposted Invoice. Why not use that instead of an extension?