[Bug]: [Quality Management] Tracking specification buffer defects in HandleOnAfterPurchRcptLineInsert
Describe the issue
Two defects in HandleOnAfterPurchRcptLineInsert, codeunit 20411 "Qlty. Receiving Integration" (src/Apps/W1/Quality Management/app/src/Integration/Receiving/QltyReceivingIntegration.Codeunit.al), the subscriber to Purch.-Post OnAfterPurchRcptLineInsert.
1. The filter cleanup clears a field that was never filtered and leaves the applied filter in place.
The filters applied to the shared var TempTrackingSpecification buffer start at :61:
TempTrackingSpecification.SetFilter("Quantity Handled (Base)", '<>0');
The cleanup block at :89-94 clears "Qty. to Invoice (Base)" (never filtered) instead of "Quantity Handled (Base)":
TempTrackingSpecification.SetRange("Qty. to Invoice (Base)");
TempTrackingSpecification.SetRange("Source ID");
...
TempTrackingSpecification is a var parameter owned by codeunit 80. The cleanup block exists precisely to hand the buffer back clean, and this typo defeats it: after the subscriber returns, posting continues with a "Quantity Handled (Base)" <> 0 filter still applied to its own buffer.
2. A single-record buffer is built and then not passed.
In the tracking loop (:79-86), TempSingleBufferTrackingSpecification is populated from the current record, inserted, and SetRecFilter() is applied, but the call on :85 passes the full multi-record buffer instead:
repeat
Clear(TempSingleBufferTrackingSpecification);
TempSingleBufferTrackingSpecification := TempTrackingSpecification;
TempSingleBufferTrackingSpecification.Insert(false);
TempSingleBufferTrackingSpecification.SetRecFilter();
AttemptCreateInspectionWithPurchaseLineAndTracking(PurchaseLine, PurchaseHeader, TempTrackingSpecification);
until TempTrackingSpecification.Next() = 0;
The zero-tracking branch a few lines above (:73-75) passes TempSingleBufferTrackingSpecification, which makes the intent clear: each iteration should hand over the isolated single tracking record. As written, the single-record buffer is dead weight; either the call should pass it, or the buffer, insert, and SetRecFilter should be removed.
Expected behavior
The cleanup clears exactly the filters that were set ("Quantity Handled (Base)" included), and the loop passes the single-record buffer it builds, or does not build it.
Steps to reproduce
Defect 1 is visible by reading :61 against :89. Defect 2 by comparing :73-75 with :79-86. Both confirmed present on current main.
Additional context
Both defects are in the same procedure and would naturally be fixed in one small PR. Suggested corrections:
For defect 1, clear the field that was actually filtered:
TempTrackingSpecification.SetRange("Quantity Handled (Base)");
instead of TempTrackingSpecification.SetRange("Qty. to Invoice (Base)"); at :89. The "Buffer Status" filter set at :62 is already cleared correctly at :94.
For defect 2, pass the single-record buffer the loop builds:
AttemptCreateInspectionWithPurchaseLineAndTracking(PurchaseLine, PurchaseHeader, TempSingleBufferTrackingSpecification);
instead of passing TempTrackingSpecification at :85, matching the zero-tracking branch at :75. If passing the full buffer positioned on the current record is intentional, then the single-record buffer, its Insert and its SetRecFilter() are dead code and should be removed instead.
I will provide a fix for a bug
- [x] I will provide a fix for a bug
:robot: AI triage completed. Product group, please validate the triage report (Microsoft internal access only, use Ctrl+Click to open in new tab).
Was this triage helpful? React with :thumbsup: or :thumbsdown: on this comment to provide feedback.
Coverage: issue-only analysis of microsoft/BCApps#9979; no code change reviewed; no implementation or fix proposed; repository evidence searched: codeunit 20411, purchase posting event publishers, Quality Management receiving tests, DME/build configuration, app dependencies, localization layers, GitHub issues/PRs, and git history; not covered: runtime reproduction, compilation, and test execution.
BC impact analysis
Affected areas
- Quality Management
- Purchase
- Item Tracking
- Posting (general)
- Events / Extensibility
Reported severity and reproducibility: Incorrect state is passed through purchase-receipt posting integration. The shared temporary tracking buffer retains a Quality Management-added filter, and tracked inspection creation receives a multi-record buffer in each loop iteration despite constructing an isolated current-record buffer. Source evidence makes the defects deterministic; runtime reproduction was not performed.
Customer-facing behavior: Purchase receipt posting can continue with a filter left on the posting-owned tracking buffer, while per-tracking inspection creation receives the full filtered tracking set instead of only the current lot or serial record. Expected behavior is an unchanged shared-buffer filter state and independently scoped processing for each tracking record.
Localizations impacted: -
First-party apps impacted: Quality Management
Potentially impacted first-party apps: Quality Management Contoso Coffee Demo Dataset
Recommendation: Recommend: Approve - The issue describes two deterministic defects in the Quality Management purchase-receipt integration, and existing tests do not detect either the multi-record inspection context or leaked filter state. History ties both behaviors to the initial Quality Management integration, while related prior regressions demonstrate that tracking-buffer contamination has produced incorrect inspection data before. No duplicate issue or existing fix was identified, and localization and app analysis found broad receiving-flow exposure without a documented design constraint.
Suggested test buckets to run in DME
- Buckets: RunALIntegrationTests_W1_Extensions
- Unmapped / needs manual bucket assignment: none
A full regression and impact analysis was generated by pr-impact-agent.