Skip to content

Fix E-Document premature Commit during Inventory Pick posting#7132

Merged
Groenbech96 merged 7 commits intomainfrom
bugs/625438
Mar 18, 2026
Merged

Fix E-Document premature Commit during Inventory Pick posting#7132
Groenbech96 merged 7 commits intomainfrom
bugs/625438

Conversation

@Groenbech96
Copy link
Contributor

@Groenbech96 Groenbech96 commented Mar 14, 2026

Summary

Fix E-Document premature Commit() during Inventory Pick posting that causes data inconsistency (Bug 625438).

Problem

When an Inventory Pick posts with an E-Document Service Flow configured, the E-Document export path executes an unconditional Commit() inside OnAfterPostSalesDoc. This commits the Sales Shipment and ILE before warehouse entries are created, causing an inventory-to-warehouse ledger mismatch if the warehouse bin check later fails.

Solution

  • Add AllowCreateEDocument guard to OnAfterPostSalesDoc, OnAfterTransferOrderPostShipment, and OnAfterPostServiceDoc subscribers to skip E-Document creation during Inventory Pick flows (when InvtPickPutaway, CommitIsSuppressed, or PreviewMode is set)
  • Subscribe to the new OnAfterPostWhseActivityCompleted event for deferred E-Document creation — this event fires after all posting work completes (including PostRelatedInboundTransfer), so the full transaction is already persisted
  • Migrate Subcontracting subscriber from obsoleted OnAfterPostWhseActivHeader to OnAfterPostWhseActivityCompleted

NAV dependency: NAV master PR 242528 (obsoletes OnAfterPostWhseActivHeader, adds OnAfterPostWhseActivityCompleted)

AB#625588
Fixes #7178

The E-Document export path (EDocExport:399) executes an unconditional
Commit() for error-isolation during XML generation. When called from
posting event subscribers during an Inventory Pick, this commits the
Sales Shipment and ILE before warehouse entries are created, causing
an inventory-to-warehouse ledger mismatch if the bin check later fails.

Changes:

EDocumentSubscribers.Codeunit.al:
- Add AllowCreateEDocument() guard to OnAfterPostSalesDoc,
  CreateEDocumentFromPostedTransferShipment, and OnAfterPostServiceDoc.
  Skips inline E-Document creation when CommitIsSuppressed,
  InvtPickPutaway, or PreviewMode is true. Logs telemetry on skip.
- Add PreviewMode to CreateEDocumentFromPostedTransferShipment params
  (publisher already emits it).
- Add OnAfterPostWhseActivHeader subscriber to create deferred
  E-Documents after the warehouse transaction completes.

SubcWhseDirectPosting.Codeunit.al:
- Accept new SuppressCommit and IsPreview parameters on
  OnAfterPostWhseActivHeader subscriber (no logic change).

Bug: AB#625438

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Groenbech96 Groenbech96 requested a review from a team as a code owner March 14, 2026 10:43
@github-actions github-actions bot added the AL: Apps (W1) Add-on apps for W1 label Mar 14, 2026
@github-actions github-actions bot added this to the Version 29.0 milestone Mar 14, 2026
Magnus Hartvig Grønbech and others added 2 commits March 16, 2026 09:54
The NAV PR obsoletes OnAfterPostWhseActivHeader (keeping original 4-param
signature) and adds a new OnAfterPostWhseActivityCompleted event that fires
after all posting work completes, including PostRelatedInboundTransfer.

- E-Document subscriber: subscribe to new event instead of the old one
- Subcontracting subscriber: revert to original 4-param signature since
  the old event retains its original contract

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The old OnAfterPostWhseActivHeader event is obsoleted and wrapped in
#if not CLEAN29. Migrate the Subcontracting subscriber to the new event
so it continues to work after the old event is removed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mazhelez and others added 4 commits March 17, 2026 06:16
The return values were swapped — normal posting (no flags) returned false
(blocking creation) while deferred scenarios returned true (allowing it).
Swap exit values so normal posting allows inline creation and suppressed
flows correctly defer to OnAfterPostWhseActivityCompleted.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
# Conflicts:
#	src/Apps/W1/EDocument/App/src/Processing/EDocumentSubscribers.Codeunit.al
@Groenbech96 Groenbech96 requested a review from a team as a code owner March 17, 2026 12:22
@github-actions github-actions bot added the Build: Automation Workflows and other setup in .github folder label Mar 17, 2026
@Groenbech96 Groenbech96 merged commit 590e653 into main Mar 18, 2026
50 checks passed
@Groenbech96 Groenbech96 deleted the bugs/625438 branch March 18, 2026 10:05
Groenbech96 added a commit that referenced this pull request Mar 18, 2026
Fix E-Document premature `Commit()` during Inventory Pick posting that
causes data inconsistency (Bug 625438).

When an Inventory Pick posts with an E-Document Service Flow configured,
the E-Document export path executes an unconditional `Commit()` inside
`OnAfterPostSalesDoc`. This commits the Sales Shipment and ILE before
warehouse entries are created, causing an inventory-to-warehouse ledger
mismatch if the warehouse bin check later fails.

- Add `AllowCreateEDocument` guard to `OnAfterPostSalesDoc`,
`OnAfterTransferOrderPostShipment`, and `OnAfterPostServiceDoc`
subscribers to skip E-Document creation during Inventory Pick flows
(when `InvtPickPutaway`, `CommitIsSuppressed`, or `PreviewMode` is set)
- Subscribe to the new `OnAfterPostWhseActivityCompleted` event for
deferred E-Document creation — this event fires after all posting work
completes (including `PostRelatedInboundTransfer`), so the full
transaction is already persisted
- Migrate Subcontracting subscriber from obsoleted
`OnAfterPostWhseActivHeader` to `OnAfterPostWhseActivityCompleted`

**NAV dependency:** NAV master PR
[242528](https://dynamicssmb2.visualstudio.com/Dynamics%20SMB/_git/NAV/pullrequest/242528)
(obsoletes `OnAfterPostWhseActivHeader`, adds
`OnAfterPostWhseActivityCompleted`)

[AB#625588](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/625588)
Fixes #7178

---------

Co-authored-by: Magnus Hartvig Grønbech <magnushar@microsoft.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: mazhelez <mazhelez@users.noreply.github.com>
Groenbech96 pushed a commit that referenced this pull request Mar 18, 2026
…Pick (#7132)

Regression test for bug 625438: verifies that when an Inventory Pick
posting fails (lot not available on the selected bin), no Posted Sales
Shipment, ILE, or E-Document is created. Also verifies the happy path
where successful posting creates all expected records including the
deferred E-Document via OnAfterPostWhseActivityCompleted.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Groenbech96 added a commit that referenced this pull request Mar 19, 2026
Fix E-Document premature `Commit()` during Inventory Pick posting that
causes data inconsistency (Bug 625438).

When an Inventory Pick posts with an E-Document Service Flow configured,
the E-Document export path executes an unconditional `Commit()` inside
`OnAfterPostSalesDoc`. This commits the Sales Shipment and ILE before
warehouse entries are created, causing an inventory-to-warehouse ledger
mismatch if the warehouse bin check later fails.

- Add `AllowCreateEDocument` guard to `OnAfterPostSalesDoc`,
`OnAfterTransferOrderPostShipment`, and `OnAfterPostServiceDoc`
subscribers to skip E-Document creation during Inventory Pick flows
(when `InvtPickPutaway`, `CommitIsSuppressed`, or `PreviewMode` is set)
- Subscribe to the new `OnAfterPostWhseActivityCompleted` event for
deferred E-Document creation — this event fires after all posting work
completes (including `PostRelatedInboundTransfer`), so the full
transaction is already persisted
- Migrate Subcontracting subscriber from obsoleted
`OnAfterPostWhseActivHeader` to `OnAfterPostWhseActivityCompleted`

**NAV dependency:** NAV master PR
[242528](https://dynamicssmb2.visualstudio.com/Dynamics%20SMB/_git/NAV/pullrequest/242528)
(obsoletes `OnAfterPostWhseActivHeader`, adds
`OnAfterPostWhseActivityCompleted`)

[AB#625588](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/625588)
Fixes #7178

---------

Co-authored-by: Magnus Hartvig Grønbech <magnushar@microsoft.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: mazhelez <mazhelez@users.noreply.github.com>
Groenbech96 added a commit that referenced this pull request Mar 19, 2026
…ng Inventory Pick posting (#7210)

## Summary

Cherry-pick of 590e653 from `main` to
`releases/28.x`.

- Fix E-Document premature `Commit()` during Inventory Pick posting that
causes data inconsistency (Bug 625438)
- Add `AllowCreateEDocument` guard to skip E-Document creation during
Inventory Pick flows
- Subscribe to `OnAfterPostWhseActivityCompleted` for deferred
E-Document creation
- Migrate Subcontracting subscriber to
`OnAfterPostWhseActivityCompleted`

Original PR: #7132


[AB#625589](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/625589)

---------

Co-authored-by: Magnus Hartvig Grønbech <magnushar@microsoft.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: mazhelez <mazhelez@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: Apps (W1) Add-on apps for W1 Build: Automation Workflows and other setup in .github folder

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants