---
id: object/codeunit/1313
type: object
title: Codeunit 1313 "Correct Posted Purch. Invoice"
summary: Codeunit 1313 "Correct Posted Purch. Invoice" in Base Application (Microsoft.Purchases.History). 10 public procedures, 22 events. Present since at least BC23, still in BC30, changed in BC24-28.
tier: official
language: en
tags:
  - codeunit
  - base application
versions:
  introduced: null
  last_changed: "28"
  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: aab71e86f8dca638c9a0cc23ec3fc6094ef03d1d4713211fe817cb9321290477
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/Purchases/History/CorrectPostedPurchInvoice.Codeunit.al
    title: src/Layers/W1/BaseApp/Purchases/History/CorrectPostedPurchInvoice.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations:
    - localization/au
    - localization/it
    - localization/nz
  videos: []
  posts: []
  guidelines: []
  changes:
    - change/bcapps/9985
object_type: codeunit
object_id: 1313
name: Correct Posted Purch. Invoice
namespace: Microsoft.Purchases.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"
  - "27"
  - "28"
source_major: "29"
obsolete: null
countries:
  - au
  - it
  - nz
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 75
  events: 22
  subscribers: 0
relations:
  out: 1
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 3
  calls: 12
  called_by: 3
  implements: 0
---

# Codeunit 1313 "Correct Posted Purch. Invoice"

> Codeunit 1313 "Correct Posted Purch. Invoice" in Base Application (Microsoft.Purchases.History). 10 public procedures, 22 events. Present since at least BC23, still in BC30, changed in BC24-28.

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

## Properties

| Property | Value |
|---|---|
| TableNo | Purch. Inv. Header |
| Permissions | TableData "Purch. Inv. Header" = rm, TableData "Purch. Cr. Memo Hdr." = rm |

## Events published

- `OnAfterCreateCorrectivePurchCrMemo(PurchInvHeader: Record "Purch. Inv. Header"; var PurchaseHeader: Record "Purchase Header"; var CancellingOnly: Boolean; var SuppressCommit: Boolean)` (integration)
- `OnAfterTestCorrectInvoiceIsAllowed(var PurchInvHeader: Record "Purch. Inv. Header"; Cancelling: Boolean)` (integration)
  - subscribers: [Codeunit 20535 "Subc. Purch. Post Ext"](../codeunit/20535.md) BlockCancelIfHasSubcontractingItemChargeValueEntry
- `OnBeforeCreateCopyDocument(var PurchInvHeader: Record "Purch. Inv. Header"; var PurchaseHeader: Record "Purchase Header"; DocumentType: Enum "Purchase Document Type"; SkipCopyFromDescription: Boolean)` (integration)
- `OnBeforeTestIfInvoiceIsPaid(var PurchInvHeader: Record "Purch. Inv. Header"; var IsHandled: Boolean)` (integration)
- `OnBeforeTestIfAnyFreeNumberSeries(var PurchInvHeader: Record "Purch. Inv. Header"; CancellingOnly: Boolean; var IsHandled: Boolean)` (integration)
- `OnBeforePurchaseHeaderInsert(var PurchaseHeader: Record "Purchase Header"; PurchInvHeader: Record "Purch. Inv. Header")` (integration)
- `OnBeforeUnAppyCostApplication(InvNo: Code[20]; var IsHandled: Boolean)` (integration)
- `OnBeforeUpdatePurchaseOrderLineInvoicedQuantity(var PurchaseLine: Record "Purchase Line"; CancelledQuantity: Decimal; CancelledQtyBase: Decimal; var IsHandled: Boolean)` (integration)
- `OnBeforeTestInventoryPostingSetup(PurchInvLine: Record "Purch. Inv. Line"; var IsHandled: Boolean)` (integration)
- `OnHasLineDiscountSetup(PurchasesPayablesSetup: Record "Purchases & Payables Setup"; var Result: Boolean)` (integration)
- `OnRunOnAfterUpdatePurchaseOrderLinesFromCancelledInvoice(var PurchInvHeader: Record "Purch. Inv. Header"; var PurchaseHeader: Record "Purchase Header")` (integration)
- `OnRunOnBeforeCreateCopyDocument(var PurchInvHeader: Record "Purch. Inv. Header")` (integration)
- `OnTestPurchaseLinesOnAfterCalcThrowItemReturnedError(PurchInvHeader: Record "Purch. Inv. Header"; PurchInvLine: Record "Purch. Inv. Line"; var ThrowItemReturnedError: Boolean)` (integration)
- `OnAfterIsCheckDirectCostAppliedAccount(PurchInvLine: Record "Purch. Inv. Line"; var Result: Boolean)` (integration)
- `OnAfterCreateCopyDocument(var PurchaseHeader: Record "Purchase Header"; SkipCopyFromDescription: Boolean; PurchInvHeader: Record "Purch. Inv. Header")` (integration)
  - subscribers: [Codeunit 5579 "Digital Voucher Impl."](../codeunit/5579.md) CopyDigitalVoucherOnAfterCreateCopyPurchDocument, [Codeunit 8074 "Document Change Management"](../codeunit/8074.md) RemoveBooleanKeyOnAfterCreateCopyPurchaseDocument
- `OnBeforeShowPostedPurchCreditMemo(var PurchCrMemoHdr: Record "Purch. Cr. Memo Hdr."; var IsHandled: Boolean)` (integration)
- `OnBeforeShowPurchaseCreditMemo(var PurchaseHeader: Record "Purchase Header"; var IsHandled: Boolean)` (integration)
- `OnCreateCreditMemoOnBeforeConfirmPostingCreditMemoFailedOpen(var PurchaseHeader: Record "Purchase Header"; var IsHandled: Boolean)` (integration)
- `OnCancelPostedInvoiceStartNewInvoiceOnAfterCreateCorrPurchaseInvoice(var PurchaseHeader: Record "Purchase Header"; var PurchInvHeader: Record "Purch. Inv. Header")` (integration)
- `OnAfterIsCommentLine(PurchInvLine: Record "Purch. Inv. Line"; var Result: Boolean)` (integration)
- `OnBeforeSetTrackInfoForCancellation(var PurchInvHeader: Record "Purch. Inv. Header"; var IsHandled: Boolean)` (integration)
- `OnBeforeTestVATPostingSetup(PurchInvLine: Record "Purch. Inv. Line"; var IsHandled: Boolean)` (integration)

## Procedures

- `CancelPostedInvoice(var PurchInvHeader: Record "Purch. Inv. Header"): Boolean`
- `CreateCreditMemoCopyDocument(var PurchInvHeader: Record "Purch. Inv. Header"; var PurchaseHeader: Record "Purchase Header"): Boolean`
- `CreateCorrectiveCreditMemo(var InvoiceNotification: Notification)`
- `ShowAppliedEntries(var InvoiceNotification: Notification)`
- `SkipCorrectiveCreditMemo(var InvoiceNotification: Notification)`
- `CancelPostedInvoiceStartNewInvoice(var PurchInvHeader: Record "Purch. Inv. Header"; var PurchaseHeader: Record "Purchase Header")`
- `TestCorrectInvoiceIsAllowed(var PurchInvHeader: Record "Purch. Inv. Header"; Cancelling: Boolean)`
- `FindItemLedgEntries(var ItemLedgEntry: Record "Item Ledger Entry"; InvNo: Code[20])`
- `ErrorHelperHeader(HeaderErrorType: Enum "Correct Purch. Inv. Error Type"; PurchInvHeader: Record "Purch. Inv. Header")`
- `UpdatePurchaseOrderLineIfExist(PurchaseCreditMemoNo: Code[20])` (internal)

Plus 43 local procedures.

## Triggers

OnRun

## Relations

- runs on [Table 122 "Purch. Inv. Header"](../table/122.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: `TestDimensionOnHeader → CheckDimIDComb`, `TestGLAccount → CheckDimValuePosting`, `TestPurchaseLines → CheckDimIDComb`, …)
- [Codeunit 6620 "Copy Document Mgt."](../codeunit/6620.md) (3 calls: `CreateCopyDocument → CopyPurchaseDocForInvoiceCancelling`, `CreateCopyDocument → SetPropertiesForCorrectiveCreditMemo`, `CreateCopyDocument → SetPropertiesForInvoiceCorrection`)
- [Codeunit 22 "Item Jnl.-Post Line"](../codeunit/22.md) (2 calls: `OnRun → RedoApplications`, `UnapplyCostApplication → UnApply`)
- [Codeunit 5817 "Undo Posting Management"](../codeunit/5817.md) (2 calls: `UpdatePurchaseOrderLinesFromCancelledInvoice → RevertPostedItemTracking`, `UpdatePurchaseOrderLinesFromCreditMemo → RevertPostedItemTracking`)
- [Page 456 "No. Series"](../page/456.md) (2 calls: `OnRun → (object)`, `TryPeekNextNo → (object)`)
- [Page 52 "Purchase Credit Memo"](../page/52.md) (2 calls: `CreateCorrectiveCreditMemo → (object)`, `CreateCreditMemo → (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 5805 "Item Charge Assgnt. (Purch.)"](../codeunit/5805.md) (1 call: `UpdateReverseItemChargeAssignment → ReverseItemChargeAssgnt`)
- [Codeunit 90 "Purch.-Post"](../codeunit/90.md) (1 call: `OnRun → (object)`)
- [Page 140 "Posted Purchase Credit Memo"](../page/140.md) (1 call: `CreateCreditMemo → (object)`)
- [Page 62 "Applied Vendor Entries"](../page/62.md) (1 call: `ShowAppliedEntries → (object)`)

## Called by

- [Codeunit 1324 "Correct PstdPurchInv (Yes/No)"](../codeunit/1324.md) (4 calls: `CancelPostedInvoice → CancelPostedInvoice`, `CancelPostedInvoiceAndOpenNewPurchaseInvoice → CancelPostedInvoiceStartNewInvoice`, `CancelPostedInvoiceAndOpenPurchaseOrder → CancelPostedInvoice`, …)
- [Codeunit 1325 "Cancel PstdPurchInv (Yes/No)"](../codeunit/1325.md) (2 calls: `CancelInvoice → CancelPostedInvoice`, `CancelInvoice → TestCorrectInvoiceIsAllowed`)
- [Table 38 "Purchase Header"](../table/38.md) (1 call: `UpdatePurchaseOrderLineIfExist → UpdatePurchaseOrderLineIfExist`)

## Recent changes

- 2026-08-07 [#9985 [Master]-For an Item of 'Type' Service or Non-Inventory we allow you to increase the Quantity of the Corrective Credit Memo which then if posted updates the Purchase Order with a negative Received and Invoiced values](../../changes/bcapps/9985.md) (main, BC30, fix)

## Across versions

- Present in: BC23-30
- Changed (declaration) in: BC24-28

## Countries that replace it

[AU](../../localizations/au.md), [IT](../../localizations/it.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 Purch. Invoice")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
