---
id: object/codeunit/1303
type: object
title: Codeunit 1303 "Correct Posted Sales Invoice"
summary: Codeunit 1303 "Correct Posted Sales Invoice" in Base Application (Microsoft.Sales.History). 10 public procedures, 36 events. Present since at least BC23, still in BC30, changed in BC24-26, BC28-29.
tier: official
language: en
tags:
  - codeunit
  - base application
versions:
  introduced: null
  last_changed: "29"
  deprecated: null
review:
  state: derived
  by: null
  at: null
  flags: []
generated:
  at: "2026-10-11T00:31:51.816Z"
  pipeline: 0.2.0
  prompts: {}
  input_hash: 9d9ebffd9df53590e6566f42371904ef83c9c18d2113a94e11120bbef801dcc1
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/Sales/History/CorrectPostedSalesInvoice.Codeunit.al
    title: src/Layers/W1/BaseApp/Sales/History/CorrectPostedSalesInvoice.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations:
    - localization/au
    - localization/nz
  videos: []
  posts: []
  guidelines: []
  changes:
    - change/bcapps/10902
    - change/bcapps/10083
    - change/bcapps/9440
object_type: codeunit
object_id: 1303
name: Correct Posted Sales Invoice
namespace: Microsoft.Sales.History
app: Base Application
extends: null
first_version: "23"
last_version: "30"
present_in:
  - "23"
  - "24"
  - "25"
  - "26"
  - "27"
  - "28"
  - "29"
  - "30"
changed_in:
  - "24"
  - "25"
  - "26"
  - "28"
  - "29"
source_major: "29"
obsolete: null
countries:
  - au
  - nz
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 91
  events: 36
  subscribers: 0
relations:
  out: 1
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 1
  calls: 11
  called_by: 6
  implements: 0
---

# Codeunit 1303 "Correct Posted Sales Invoice"

> Codeunit 1303 "Correct Posted Sales Invoice" in Base Application (Microsoft.Sales.History). 10 public procedures, 36 events. Present since at least BC23, still in BC30, changed in BC24-26, BC28-29.

Base Application · Microsoft.Sales.History · BC23-30 · [source at ea08af5e](https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/Sales/History/CorrectPostedSalesInvoice.Codeunit.al) · facts from BC29

## Properties

| Property | Value |
|---|---|
| TableNo | Sales Invoice Header |
| Permissions | TableData "Sales Invoice Header" = rm, TableData "Sales Cr.Memo Header" = rm |

## Events published

- `OnAfterCreateCopyDocument(var SalesHeader: Record "Sales Header"; var SalesInvoiceHeader: Record "Sales Invoice Header")` (integration): Raised after creating a copy document from a posted sales invoice.
- `OnBeforeTestIfDropShipmentDocument(var SalesInvoiceHeader: Record "Sales Invoice Header"; var IsHandled: Boolean)` (integration): Raised before testing whether to drop shipment document exists for the posted sales invoice.
- `OnAfterIsCommentLine(SalesInvoiceLine: Record "Sales Invoice Line"; var Result: Boolean)` (integration): Raised after determining whether a sales invoice line is a comment line.
- `OnAfterTestCorrectInvoiceIsAllowed(var SalesInvoiceHeader: Record "Sales Invoice Header"; Cancelling: Boolean)` (integration): Raised after testing whether the invoice correction or cancellation is allowed.
- `OnAfterTestSalesLineType(SalesInvoiceLine: Record "Sales Invoice Line"; var IsHandled: Boolean)` (integration): Raised after testing whether the sales invoice line type is allowed for correction.
- `OnAfterCreateCorrSalesInvoice(var SalesHeader: Record "Sales Header"; var SalesInvoiceHeader: Record "Sales Invoice Header")` (integration): Raised after creating a corrective sales invoice from a posted invoice.
- `OnAfterCreateCorrectiveSalesCrMemo(SalesInvoiceHeader: Record "Sales Invoice Header"; var SalesHeader: Record "Sales Header"; var CancellingOnly: Boolean)` (integration): Raised after creating a corrective sales credit memo from a posted invoice.
  - subscribers: [Codeunit 5579 "Digital Voucher Impl."](../codeunit/5579.md) CopyDigitalVoucherOnAfterCreateCorrectiveSalesCrMemo
- `OnAfterUpdateSalesOrderLineInvoicedQuantity(var SalesLine: Record "Sales Line"; CancelledQuantity: Decimal; CancelledQtyBase: Decimal)` (integration): Raised after updating the invoiced quantity on a sales order line during cancellation.
- `OnBeforeCreateCorrectiveSalesCrMemo(var SalesInvoiceHeader: Record "Sales Invoice Header")` (integration): Raised before creating a corrective sales credit memo from a posted invoice.
- `OnBeforeCreateCreditMemoCopyDocument(var SalesInvoiceHeader: Record "Sales Invoice Header")` (integration): Raised before creating a credit memo copy document from a posted invoice.
- `OnCreateCreditMemoCopyDocumentOnBeforeConfirm(var SalesInvoiceHeader: Record "Sales Invoice Header"; var SalesHeader: Record "Sales Header"; var ConfirmQuestion: Text)` (integration): Raised before confirming the creation of a corrective credit memo for an invoice posted from a sales order.
- `OnBeforeSalesHeaderInsert(var SalesHeader: Record "Sales Header"; var SalesInvoiceHeader: Record "Sales Invoice Header"; CancellingOnly: Boolean)` (integration): Raised before inserting the sales header during invoice correction.
- `OnBeforeSetTrackInfoForCancellation(var SalesInvoiceHeader: Record "Sales Invoice Header"; var IsHandled: Boolean)` (integration): Raised before setting tracking information for invoice cancellation.
- `OnBeforeTestIfAnyFreeNumberSeries(var SalesInvoiceHeader: Record "Sales Invoice Header"; var IsHandled: Boolean)` (integration): Raised before testing whether there are free number series for the correction.
- `OnHasLineDiscountSetup(SalesReceivablesSetup: Record "Sales & Receivables Setup"; var Result: Boolean)` (integration): Raised to determine whether line discount setup is configured.
- `OnBeforeTestInventoryPostingSetup(SalesInvoiceLine: Record "Sales Invoice Line"; var IsHandled: Boolean)` (integration): Raised before testing inventory posting setup for the sales invoice line.
- `OnBeforeUpdateSalesOrderLineInvoicedQuantity(var SalesLine: Record "Sales Line"; CancelledQuantity: Decimal; CancelledQtyBase: Decimal; var IsHandled: Boolean)` (integration): Raised before updating the invoiced quantity on a sales order line during cancellation.
- `OnUpdateSalesOrderLinePrepmtAmountOnBeforeUpdatePrepmtAmounts(SalesInvoiceLine: Record "Sales Invoice Line"; var SalesLine: Record "Sales Line"; SalesHeader: Record "Sales Header"; Currency: Record Currency; var IsHandled: Boolean)` (integration): Raised before updating prepayment amounts on a sales order line during correction.
- `OnCreateCreditMemoOnBeforePageRun(var SalesHeader: Record "Sales Header"; var IsHandled: Boolean)` (integration): Raised before opening the credit memo page during invoice correction.
- `OnCreateCreditMemoOnBeforePostedPageRun(var SalesCrMemoHeader: Record "Sales Cr.Memo Header"; var IsHandled: Boolean)` (integration): Raised before opening the posted credit memo page during invoice correction.
- `OnBeforeUnapplyCostApplication(InvNo: Code[20]; var IsHandled: Boolean)` (integration): Raised before unapplying cost applications for the invoice.
- `OnTestSalesLinesOnAfterCalcShippedQtyNoReturned(SalesInvoiceLine: Record "Sales Invoice Line"; var ShippedQtyNoReturned: Decimal)` (integration): Raised after calculating the shipped quantity not returned during sales line validation.
- `OnOnRunOnAfterUpdateSalesOrderLinesFromCancelledInvoice(var Rec: Record "Sales Invoice Header"; var SalesHeader: Record "Sales Header")` (integration): Raised after updating sales order lines from a cancelled invoice during the OnRun trigger.
- `OnBeforeTestIfInvoiceIsPaid(var SalesInvoiceHeader: Record "Sales Invoice Header"; var IsHandled: Boolean)` (integration): Raised before testing whether the invoice has been paid.
- `OnCreateCorrectiveCreditMemoOnBeforePageRun(var SalesHeader: Record "Sales Header"; var IsHandled: Boolean)` (integration): Raised before opening the corrective credit memo page from a notification action.
- `OnBeforeTestVATPostingSetup(SalesInvoiceLine: Record "Sales Invoice Line"; var IsHandled: Boolean)` (integration): Raised before testing VAT posting setup for the sales invoice line.
- `OnBeforeErrorHelperHeader(HeaderErrorType: Enum "Correct Sales Inv. Error Type"; SalesInvoiceHeader: Record "Sales Invoice Header"; CancellingOnly: Boolean)` (integration): Raised before raising a header-level error during invoice correction validation.
- `OnBeforeTestIfInvoiceIsCorrectedOnce(var SalesInvoiceHeader: Record "Sales Invoice Header"; var IsHandled: Boolean)` (integration): Raised before testing whether the invoice has already been corrected.
- `OnBeforeWasNotCancelled(InvNo: Code[20]; var Result: Boolean; var IsHandled: Boolean)` (integration): Raised before checking whether the invoice was not cancelled.
- `OnRunOnBeforePostCorrectiveSalesCrMemo(var SalesInvoiceHeader: Record "Sales Invoice Header"; var SalesHeader: Record "Sales Header"; var IsHandled: Boolean; var SuppressCommit: Boolean)` (integration): Raised before posting the corrective sales credit memo during the OnRun trigger.
- `OnBeforeTestWMSLocation(var SalesInvoiceLine: Record "Sales Invoice Line"; var IsHandled: Boolean)` (integration): Raised before testing warehouse management system location for the sales invoice line.
- `OnBeforeCreateAndProcessJobPlanningLines(var SalesHeader: Record "Sales Header"; var IsHandled: Boolean)` (integration): Raised before creating and processing project planning lines during invoice correction.
- `OnTestGenPostingSetupOnBeforeTestTypeItem(SalesInvoiceLine: Record "Sales Invoice Line"; var IsHandled: Boolean)` (integration): Raised before testing general posting setup for item type lines.
- `OnBeforeUpdateSalesOrderLinesFromCancelledInvoice(SalesInvoiceHeaderNo: Code[20]; var IsHandled: Boolean)` (integration): Raised before updating sales order lines from a cancelled invoice.
- `OnBeforeUpdateSalesOrderLinesFromCreditMemo(var SalesInvoiceLine: Record "Sales Invoice Line"; var SalesCrMemoLine: Record "Sales Cr.Memo Line"; var IsHandled: Boolean)` (integration): Raised before updating sales order lines from a credit memo.
- `OnCreateJobPlanningLineOnAfterInitFromJobPlanningLine(var ToJobPlanningLine: Record "Job Planning Line"; FromJobPlanningLine: Record "Job Planning Line"; SalesLine: Record "Sales Line")` (integration): Raised after initializing a project planning line from another project planning line during correction.

## Procedures

- `CancelPostedInvoice(var SalesInvoiceHeader: Record "Sales Invoice Header"): Boolean`: Cancels the posted sales invoice by creating and posting a corrective credit memo.
- `CreateCreditMemoCopyDocument(var SalesInvoiceHeader: Record "Sales Invoice Header"; var SalesHeader: Record "Sales Header"): Boolean`: Creates a credit memo document as a copy of the posted sales invoice without posting it.
- `CreateCorrectiveCreditMemo(var InvoiceNotification: Notification)`: Creates a corrective credit memo from a notification action triggered on a posted sales invoice.
- `ShowAppliedEntries(var InvoiceNotification: Notification)`: Shows the applied customer ledger entries for the posted sales invoice referenced in the notification.
- `SkipCorrectiveCreditMemo(var InvoiceNotification: Notification)`: Dismisses the corrective credit memo notification without taking any action.
- `CancelPostedInvoiceCreateNewInvoice(var SalesInvoiceHeader: Record "Sales Invoice Header"; var SalesHeader: Record "Sales Header")`: Cancels the posted sales invoice and creates a new sales invoice as a copy for correction.
- `TestCorrectInvoiceIsAllowed(var SalesInvoiceHeader: Record "Sales Invoice Header"; Cancelling: Boolean)`: Tests whether the posted sales invoice can be corrected or canceled by checking payment status, customer blocks, and other conditions.
- `FindItemLedgEntries(var ItemLedgEntry: Record "Item Ledger Entry"; InvNo: Code[20])`: Finds all item ledger entries associated with the specified posted sales invoice.
- `ErrorHelperHeader(HeaderErrorType: Enum "Correct Sales Inv. Error Type"; SalesInvoiceHeader: Record "Sales Invoice Header")`: Raises an error message based on the header error type encountered during invoice correction validation.
- `UpdateSalesOrderLineIfExist(SalesCreditMemoNo: Code[20])` (internal): Updates the related sales order lines when a credit memo exists for the specified credit memo number.

Plus 45 local procedures.

## Triggers

OnRun

## Relations

- runs on [Table 112 "Sales Invoice Header"](../table/112.md)

## Calls

From the extracted call graph of BC29 (graphify-al on the snapshot checkout): calls whose target is known from a declared type or an `Object::"Name"` argument. Interface dispatch and calls through events are not counted, so the list is not complete.

- [Codeunit 408 "DimensionManagement"](../codeunit/408.md) (5 calls: `TestCustomerDimension → CheckDimValuePosting`, `TestDimensionOnHeader → CheckDimIDComb`, `TestGLAccount → CheckDimValuePosting`, …)
- [Codeunit 6620 "Copy Document Mgt."](../codeunit/6620.md) (3 calls: `CreateCopyDocument → CopySalesDocForInvoiceCancelling`, `CreateCopyDocument → SetPropertiesForCorrectiveCreditMemo`, `CreateCopyDocument → SetPropertiesForInvoiceCorrection`)
- [Codeunit 22 "Item Jnl.-Post Line"](../codeunit/22.md) (2 calls: `UnapplyCostApplication → RedoApplications`, `UnapplyCostApplication → UnApply`)
- [Codeunit 5817 "Undo Posting Management"](../codeunit/5817.md) (2 calls: `UpdateSalesOrderLinesFromCancelledInvoice → RevertPostedItemTracking`, `UpdateSalesOrderLinesFromCreditMemo → RevertPostedItemTracking`)
- [Page 44 "Sales Credit Memo"](../page/44.md) (2 calls: `CreateCorrectiveCreditMemo → (object)`, `CreateCreditMemo → (object)`)
- [Page 456 "No. Series"](../page/456.md) (2 calls: `OnRun → (object)`, `TryPeekNextNo → (object)`)
- [Codeunit 11 "Gen. Jnl.-Check Line"](../codeunit/11.md) (1 call: `TestIfPostingIsAllowed → DateNotAllowed`)
- [Codeunit 1511 "Notification Lifecycle Mgt."](../codeunit/1511.md) (1 call: `ShowInvoiceAppliedNotification → SendNotification`)
- [Codeunit 700 "Page Management"](../codeunit/700.md) (1 call: `CreateCreditMemo → PageRun`)
- [Codeunit 80 "Sales-Post"](../codeunit/80.md) (1 call: `OnRun → (object)`)
- [Page 61 "Applied Customer Entries"](../page/61.md) (1 call: `ShowAppliedEntries → (object)`)

## Called by

- [Codeunit 1322 "Correct PstdSalesInv (Yes/No)"](../codeunit/1322.md) (4 calls: `CancelPostedInvoice → CancelPostedInvoice`, `CancelPostedInvoiceAndOpenNewSalesInvoice → CancelPostedInvoiceCreateNewInvoice`, `CancelPostedInvoiceAndOpenSalesOrder → CancelPostedInvoice`, …)
- [Page 20012 "APIV1 - Sales Invoices"](../page/20012.md) (3 calls: `CancelInvoice → (object)`, `CheckInvoiceCanBeCanceled → TestCorrectInvoiceIsAllowed`, `MakeCorrectiveCreditMemo → CreateCreditMemoCopyDocument`)
- [Page 30012 "APIV2 - Sales Invoices"](../page/30012.md) (3 calls: `CancelInvoice → (object)`, `CheckInvoiceCanBeCanceled → TestCorrectInvoiceIsAllowed`, `MakeCorrectiveCreditMemo → CreateCreditMemoCopyDocument`)
- [Codeunit 1323 "Cancel PstdSalesInv (Yes/No)"](../codeunit/1323.md) (2 calls: `CancelInvoice → CancelPostedInvoice`, `CancelInvoice → TestCorrectInvoiceIsAllowed`)
- [Codeunit 80 "Sales-Post"](../codeunit/80.md) (1 call: `UpdateSalesOrderLineIfExist → UpdateSalesOrderLineIfExist`)
- [Table 36 "Sales Header"](../table/36.md) (1 call: `UpdateSalesOrderLineIfExist → UpdateSalesOrderLineIfExist`)

## Recent changes

- 2026-09-02 [#10902 [Extensibility Request] issue 30424: add prepayment update event](../../changes/bcapps/10902.md) (main, BC30, feature)
- 2026-08-11 [#10083 [main]- Negative Shipped and Invoiced Quantities appear on Sales Order Lines after using the Copy Document from a Sales Credit Memo.](../../changes/bcapps/10083.md) (main, BC30, fix)
- 2026-07-15 [#9440 [Extensibility Request] issue 30331: add event to adjust corrective credit memo confirmation text](../../changes/bcapps/9440.md) (main, BC30, feature)

## Across versions

- Present in: BC23-30
- Changed (declaration) in: BC24-26, BC28-29

## Countries that replace it

[AU](../../localizations/au.md), [NZ](../../localizations/nz.md)

Source: AL metadata extracted from the code (names, ids, signatures, properties); no code bodies (D10).

## Ask your agent

Procedure bodies are not stored here (D10). The call sections above are our own, per object, from the BC29 call graph. For a procedure body or the calls of one procedure, ask bc-code-atlas (external, by Stefan Maron, MIT; default corpus w1-28), which the bc-observatory plugin connects: `bcatlas_resolve_node(object_type: "codeunit", object_name: "Correct Posted Sales Invoice")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
