Credit Memo from a Posted Invoice
A customer returned the goods from an invoice you already posted, and accounting wants a one-call routine that drafts the paperwork: a sales credit memo that mirrors the posted invoice, stamped with the invoice number it reverses. Business Central already ships the copying engine — codeunit 6620 "Copy Document Mgt.", the code behind the Copy Document action — so your job is to drive it from code and hook your stamp into it.
Requirements
- Create a table extension for the
Sales Headertable with a field named"Source Invoice No."of typeCode[20]. - Create a codeunit named
"Credit Memo From Invoice"with this exact procedure:
procedure CreateFromPostedInvoice(PostedInvoiceNo: Code[20]; var CreditMemoHeader: Record "Sales Header")- The procedure must create a new sales credit memo (a
Sales Headerwith"Document Type" = "Credit Memo", numbered from the standard number series) and fill it from the posted sales invoicePostedInvoiceNousing codeunit 6620"Copy Document Mgt."— header included, lines not recalculated. On return,CreditMemoHeaderis the created credit memo.
Pro problem
Solve it with Pro
You’re reading the opening of the statement. Pro unlocks the whole problem:
- The full statement
- Starter code in the browser editor
- 10 grading tests, run on Business Central 28.5
- 3 hints
- The reference solution
Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.
$10 / month
or $100 / year
Upgrade
Already on Pro? Sign in
This problem is part of Pro
Pro unlocks the full statement, tests, hints and solution. The code editor works on a computer.
Upgrade