5003

Credit Memo from a Posted Invoice

Basics
Medium
Pro
copy-document
credit-memo
sales
event-subscriber
table-extension

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

  1. Create a table extension for the Sales Header table with a field named "Source Invoice No." of type Code[20].
  2. Create a codeunit named "Credit Memo From Invoice" with this exact procedure:
procedure CreateFromPostedInvoice(PostedInvoiceNo: Code[20]; var CreditMemoHeader: Record "Sales Header")
  1. The procedure must create a new sales credit memo (a Sales Header with "Document Type" = "Credit Memo", numbered from the standard number series) and fill it from the posted sales invoice PostedInvoiceNo using codeunit 6620 "Copy Document Mgt." — header included, lines not recalculated. On return, CreditMemoHeader is the created credit memo.
The rest of the statement and 3 hints Unlock with Pro
ALBusiness Central 28.5
Pro
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
This problem is part of Pro
Pro unlocks the full statement, tests, hints and solution. The code editor works on a computer.
Upgrade