---
id: change/bcapps/14138
type: change
title: "#14138 [MAIN] Fix undo of final subcontracting operation after earlier operation undo (Bug 653934)"
summary: Fixed a bug where undoing the final subcontracting operation on a posted purchase receipt failed with an "Applies-to Entry must have a value" error when an earlier operation had already been undone. The capacity ledger entry lookup is now scoped to the receipt line's routing details and excludes reversal entries.
tier: official
language: en
tags:
  - fix
  - main
  - bc30
  - codeunit mfg. undo purch. rcpt. line
system: purchasing
review:
  state: reviewed
  by: opus
  at: "2026-11-21T00:56:52.498Z"
  flags: []
generated:
  at: "2026-12-03T00:18:19.990Z"
  pipeline: 0.2.0
  prompts:
    extract-change: 1
  input_hash: 0f22df5e9e47eec625d1ba7c0004bab7e25c6006
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/pull/14138
    title: "microsoft/BCApps#14138: [MAIN] Fix undo of final subcontracting operation after earlier operation undo (Bug 653934)"
    date: "2026-11-20"
    commit: 0f22df5e9e47eec625d1ba7c0004bab7e25c6006
    t: null
    quote: null
links:
  learn: []
  objects:
    - object/codeunit/99000784
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  changes: []
  related:
    - to: https://learn.microsoft.com/dynamics365/business-central/contoso-coffee/manufacturing/set-up-process-subcontracting-operation
      title: Set Up and Process a Subcontracting Operation
      label: possibly related
      why: Demonstrates subcontracting operations including undoing purchase receipt lines.
      by: model
    - to: https://learn.microsoft.com/dynamics365/business-central/production-how-to-subcontract-manufacturing
      title: Subcontracting overview
      label: possibly related
      why: Overview of subcontracting operations that this undo fix supports.
      by: model
number: 14138
repo: microsoft/BCApps
source_id: bcapps-prs
url: https://github.com/microsoft/BCApps/pull/14138
kind: pr
base_branch: main
major: "30"
merged_at: "2026-11-20T14:50:19Z"
author: alexei-dobriansky
author_type: User
community_contribution: false
labels:
  - "AL: Apps (W1)"
  - "Team: SCM"
change_class: code
change_kind: fix
behavior_change: true
breaking: false
files:
  count: 2
  additions: 199
  deletions: 1
  al: 1
apps:
  - Base Application
objects_touched:
  - key: codeunit/99000784
    page: codeunit/99000784
    type: codeunit
    id: 99000784
    name: Mfg. Undo Purch. Rcpt. Line
    app: Base Application
    status: modified
objects_unjoined: []
obsoletions: []
backports:
  - number: 14393
    base: releases/29.x
    url: https://github.com/microsoft/BCApps/pull/14393
fixes_issues: []
work_items:
  - 653934
systems:
  - purchasing
quote: null
joined_against:
  major: "30"
  commit: d2abc1d2ceae394331716c8183ef60e1534c2ce0
---

# #14138 [MAIN] Fix undo of final subcontracting operation after earlier operation undo (Bug 653934)

> Fixed a bug where undoing the final subcontracting operation on a posted purchase receipt failed with an "Applies-to Entry must have a value" error when an earlier operation had already been undone. The capacity ledger entry lookup is now scoped to the receipt line's routing details and excludes reversal entries.

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

## What changed

- Capacity ledger entry lookup now filters by receipt line's Routing No., Routing Reference No., and Operation No. to find the correct entry
- Reversal entries are excluded from the lookup to prevent selecting the wrong register after an earlier undo
- Output item ledger entries are only collected when the original capacity entry is the last output operation
- Undoing intermediate operations now reverses only their capacity using their own time values
- New test cases added to verify correct undo behavior for multiple subcontracting operations on the same receipt
- Behaviour changes for users or extensions.

## AL objects touched

- [Codeunit 99000784 "Mfg. Undo Purch. Rcpt. Line"](../../objects/codeunit/99000784.md), Base Application: modified

## Also merged into

- [#14393](https://github.com/microsoft/BCApps/pull/14393) into `releases/29.x` on 2026-12-02

## Context

- Work items: AB#653934
- Labels: AL: Apps (W1), Team: SCM
- Systems: purchasing

## Possibly related

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

- [Set Up and Process a Subcontracting Operation](https://learn.microsoft.com/dynamics365/business-central/contoso-coffee/manufacturing/set-up-process-subcontracting-operation) — possibly related: Demonstrates subcontracting operations including undoing purchase receipt lines. (model-linked)
- [Subcontracting overview](https://learn.microsoft.com/dynamics365/business-central/production-how-to-subcontract-manufacturing) — possibly related: Overview of subcontracting operations that this undo fix supports. (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).
