---
id: change/bcapps/14687
type: change
title: '#14687 [Main] [All-e]Correct/Cancel on Posted Purchase Invoice fails with "External Document No. must have a value" when Ext. Doc. No. Mandatory and Calc. Inv. Discount are enabled and Credit Memo Nos. and  Posted Credit Memo Nos. has the same code'
summary: Correct and Cancel on a posted purchase invoice no longer fail with External Document No. must have a value when Ext. Doc. No. Mandatory and Calc. Inv. Discount are on and credit memo series match. The corrective credit memo header is now saved right after its vendor reference is set.
tier: official
language: en
tags:
  - fix
  - main
  - bc30
  - codeunit correct posted purch. invoice
system: purchasing
review:
  state: reviewed
  by: opus
  at: "2026-12-04T01:06:55.824Z"
  flags: []
generated:
  at: "2026-12-05T00:13:03.967Z"
  pipeline: 0.2.0
  prompts:
    extract-change: 1
  input_hash: c7b6ce79a4e114de2261e83fd8bbf10c547a665d
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/pull/14687
    title: 'microsoft/BCApps#14687: [Main] [All-e]Correct/Cancel on Posted Purchase Invoice fails with "External Document No. must have a value" when Ext. Doc. No. Mandatory and Calc. Inv. Discount are enabled and Credit Memo Nos. and  Posted Credit Memo Nos. has the same code'
    date: "2026-12-03"
    commit: c7b6ce79a4e114de2261e83fd8bbf10c547a665d
    t: null
    quote: Save the corrective credit memo header immediately after assigning its vendor reference using PurchaseHeader.Modify()
links:
  learn: []
  objects:
    - object/codeunit/1313
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  changes: []
  related:
    - to: https://learn.microsoft.com/dynamics365/business-central/purchasing-how-correct-cancel-unpaid-purchase-invoices
      title: Amend or cancel unpaid purchase invoices
      label: possibly related
      why: Correct/Cancel on posted purchase invoice documents the correction process for purchase invoices.
      by: model
number: 14687
repo: microsoft/BCApps
source_id: bcapps-prs
url: https://github.com/microsoft/BCApps/pull/14687
kind: pr
base_branch: main
major: "30"
merged_at: "2026-12-03T13:03:37Z"
author: sanjmaurya
author_type: User
community_contribution: false
labels:
  - "Team: SCM"
change_class: code
change_kind: fix
behavior_change: true
breaking: false
files:
  count: 11
  additions: 712
  deletions: 1
  al: 4
apps:
  - Base Application
objects_touched:
  - key: codeunit/1313
    page: codeunit/1313
    type: codeunit
    id: 1313
    name: Correct Posted Purch. Invoice
    app: Base Application
    status: modified
objects_unjoined:
  - path: src/Layers/ES/BaseApp/Purchases/History/CorrectPostedPurchInvoice.Codeunit.al
    status: modified
    reason: not-in-snapshot
obsoletions: []
backports: []
fixes_issues: []
work_items:
  - 659717
systems:
  - purchasing
quote: Save the corrective credit memo header immediately after assigning its vendor reference using PurchaseHeader.Modify()
joined_against:
  major: "30"
  commit: f53bb0f1ecd89fde9f133f9dcaf5bf43cf5f2671
---

# #14687 [Main] [All-e]Correct/Cancel on Posted Purchase Invoice fails with "External Document No. must have a value" when Ext. Doc. No. Mandatory and Calc. Inv. Discount are enabled and Credit Memo Nos. and  Posted Credit Memo Nos. has the same code

> Correct and Cancel on a posted purchase invoice no longer fail with External Document No. must have a value when Ext. Doc. No. Mandatory and Calc. Inv. Discount are on and credit memo series match. The corrective credit memo header is now saved right after its vendor reference is set.

[Pull request](https://github.com/microsoft/BCApps/pull/14687) · merged into `main` (BC30) on 2026-12-03 by sanjmaurya · 11 files (+712 -1), 4 AL · fix · tier official · reviewed (checked by Opus)

## What changed

- Corrective credit memo header is now saved immediately after vendor reference assignment
- Prevents loss of vendor reference during invoice discount calculation
- Fixes both Correct and Cancel operations on posted purchase invoices
- Regression tests added for matching and different number series scenarios
- Behaviour changes for users or extensions.

## AL objects touched

- [Codeunit 1313 "Correct Posted Purch. Invoice"](../../objects/codeunit/1313.md), Base Application: modified
- `src/Layers/ES/BaseApp/Purchases/History/CorrectPostedPurchInvoice.Codeunit.al`: modified, not in the BC30 snapshot

## Context

- Work items: AB#659717
- Labels: Team: SCM
- Systems: purchasing
- From the description: "Save the corrective credit memo header immediately after assigning its vendor reference using PurchaseHeader.Modify()"

## Possibly related

No source states these links: they share an object, a model read them, or a person found the same subject.

- [Amend or cancel unpaid purchase invoices](https://learn.microsoft.com/dynamics365/business-central/purchasing-how-correct-cancel-unpaid-purchase-invoices) — possibly related: Correct/Cancel on posted purchase invoice documents the correction process for purchase invoices. (model-linked)

Source: metadata of a merged pull request in microsoft/BCApps (bcapps): title, labels, changed paths and counts, with a summary in our words. No source text and no description beyond one short quote (D10, D61).
