---
id: change/bcapps/10254
type: change
title: "#10254 Fix 644744: Undo subcontracting receipt keys Item Entry Relation with Capacity Ledger Entry No."
summary: Subcontracting purchase receipt undo now uses the correct Output Item Ledger Entry instead of the Capacity Ledger Entry No. when recording item entry relations, preventing data corruption and duplicate key errors for tracked items.
tier: official
language: en
tags:
  - fix
  - main
  - bc30
  - codeunit undo posting management
system: inventory
review:
  state: reviewed
  by: opus
  at: "2026-10-08T02:08:12.756Z"
  flags: []
generated:
  at: "2026-10-08T01:26:53.141Z"
  pipeline: 0.2.0
  prompts:
    extract-change: 1
  input_hash: a93b43dc9ae63ab6a73f4a96e2e6b3b0d9705527
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/pull/10254
    title: "microsoft/BCApps#10254: Fix 644744: Undo subcontracting receipt keys Item Entry Relation with Capacity Ledger Entry No."
    date: "2026-08-20"
    commit: a93b43dc9ae63ab6a73f4a96e2e6b3b0d9705527
    t: null
    quote: null
links:
  learn: []
  objects:
    - object/codeunit/5817
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  changes: []
number: 10254
repo: microsoft/BCApps
source_id: bcapps-prs
url: https://github.com/microsoft/BCApps/pull/10254
kind: pr
base_branch: main
major: "30"
merged_at: "2026-08-20T07:27:33Z"
author: alexei-dobriansky
author_type: User
community_contribution: false
labels:
  - "AL: Apps (W1)"
  - Subcontracting
  - "Team: SCM"
change_class: code
change_kind: fix
behavior_change: true
breaking: false
files:
  count: 3
  additions: 198
  deletions: 6
  al: 1
apps:
  - Base Application
objects_touched:
  - key: codeunit/5817
    page: codeunit/5817
    type: codeunit
    id: 5817
    name: Undo Posting Management
    app: Base Application
    status: modified
objects_unjoined: []
obsoletions: []
backports: []
fixes_issues: []
work_items:
  - 644744
systems:
  - inventory
quote: null
joined_against:
  major: "30"
  commit: ecbc028c25dbe83b61313bc566e6c1d41184bb1c
---

# #10254 Fix 644744: Undo subcontracting receipt keys Item Entry Relation with Capacity Ledger Entry No.

> Subcontracting purchase receipt undo now uses the correct Output Item Ledger Entry instead of the Capacity Ledger Entry No. when recording item entry relations, preventing data corruption and duplicate key errors for tracked items.

[Pull request](https://github.com/microsoft/BCApps/pull/10254) · merged into `main` (BC30) on 2026-08-20 by alexei-dobriansky · 3 files (+198 -6), 1 AL · fix · tier official · reviewed (checked by Opus)

## What changed

- Undo of tracked subcontracting receipts now keys item entry relations from the actual posted Output Item Ledger Entry, not the capacity entry number
- Fixes silent corruption and duplicate key errors in Item Entry Relation table for multi-output or tracked subcontracting undo
- Normal items and single-line capacity-only undo paths remain unaffected
- New tests verify the fix handles tracked undo correctly and guards against non-last-operation scenarios
- Previously disabled test for undo with lot tracking re-enabled
- Behaviour changes for users or extensions.

## AL objects touched

- [Codeunit 5817 "Undo Posting Management"](../../objects/codeunit/5817.md), Base Application: modified

## Context

- Work items: AB#644744
- Labels: AL: Apps (W1), Subcontracting, Team: SCM
- Systems: inventory

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).
