Restore WorkDate after E-Document DE demo data generation on error#30006
Closed
jeffreybulanadi wants to merge 1 commit into
Closed
Restore WorkDate after E-Document DE demo data generation on error#30006jeffreybulanadi wants to merge 1 commit into
jeffreybulanadi wants to merge 1 commit into
Conversation
…ails When ContosoInboundEDocument.Generate() throws during demo data setup, WorkDate() was left permanently modified for the remainder of the session. Extracted the document generation calls into a TryFunction so that WorkDate is guaranteed to be restored before the error propagates, regardless of which invoice fails to process. Relates to issue https://github.com/microsoft/ALAppExtensions/issues/29644
1 task
Contributor
|
Issue #26944 is not valid. Please make sure you link an issue that exists, is open and is approved. |
Contributor
|
👋 Thanks for your contribution! This repository is no longer accepting new pull requests. 👉 Please submit your contribution to https://github.com/microsoft/BCApps instead, once all apps have been migrated (expected mid/end of May 2026). We appreciate your understanding and look forward to your contribution in the new collaboration hub 🙌 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relates to microsoft/BCApps#8707
Fixes microsoft/BCApps#8707
Root cause
When the Contoso demo tool ran E-Document DE demo data, the previous code in
EDocDemodataDEcalledCreate Demo EDocs DEat the Transactional level. That codeunit calledContosoInboundEDocument.Generate(), which internally ran the "Finish draft" import step. Because theCreateEDocSampleInvoicesevent subscriber was not bound at that point, the purchase header update event did not fire, causing the "Finish draft" processing to fail and leaveDocument Record IDunset. The subsequentTestField("Document Record ID")call inPostPurchaseInvoicethen surfaced the confusing validation error.The invocation of
Create Demo EDocs DEwas removed fromEDocDemodataDEas part of the v29 realignment, which resolves the crash. This PR addresses a secondary problem that was exposed by the same scenario:WorkDatewas modified before theGenerate()calls and only restored at the very end of the procedure. If anyGenerate()call threw an error,WorkDatewas left permanently modified for the remainder of the session.Changes
In
CreateDemoEDocsDE(codeunit 11370, pending obsolete since 28.0):Generate()calls into a[TryFunction]procedure namedTryCreateInboundEDocuments.GenerateContosoInboundEDocumentsnow saves and restoresWorkDatearound a call toTryCreateInboundEDocuments, guaranteeing restoration even when an error occurs.WorkDateis restored before the original error text is re-raised, preserving the original error message and behavior while preventing global state from being corrupted.How to test
WorkDatereturns to its original value after the demo data run completes, regardless of whether any individual E-Document invoice failed during generation.Expected behavior
Generate()call fails for any reason,WorkDateis restored to its value before demo data generation started, and the original error message is surfaced to the caller.