Skip to content

Restore WorkDate after E-Document DE demo data generation on error#30006

Closed
jeffreybulanadi wants to merge 1 commit into
microsoft:mainfrom
jeffreybulanadi:feature/29644-de-edoc-demo-data-workdate-guard
Closed

Restore WorkDate after E-Document DE demo data generation on error#30006
jeffreybulanadi wants to merge 1 commit into
microsoft:mainfrom
jeffreybulanadi:feature/29644-de-edoc-demo-data-workdate-guard

Conversation

@jeffreybulanadi

@jeffreybulanadi jeffreybulanadi commented May 5, 2026

Copy link
Copy Markdown

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 EDocDemodataDE called Create Demo EDocs DE at the Transactional level. That codeunit called ContosoInboundEDocument.Generate(), which internally ran the "Finish draft" import step. Because the CreateEDocSampleInvoices event subscriber was not bound at that point, the purchase header update event did not fire, causing the "Finish draft" processing to fail and leave Document Record ID unset. The subsequent TestField("Document Record ID") call in PostPurchaseInvoice then surfaced the confusing validation error.

The invocation of Create Demo EDocs DE was removed from EDocDemodataDE as part of the v29 realignment, which resolves the crash. This PR addresses a secondary problem that was exposed by the same scenario: WorkDate was modified before the Generate() calls and only restored at the very end of the procedure. If any Generate() call threw an error, WorkDate was left permanently modified for the remainder of the session.

Changes

In CreateDemoEDocsDE (codeunit 11370, pending obsolete since 28.0):

  • Extracted the eight Generate() calls into a [TryFunction] procedure named TryCreateInboundEDocuments.
  • GenerateContosoInboundEDocuments now saves and restores WorkDate around a call to TryCreateInboundEDocuments, guaranteeing restoration even when an error occurs.
  • If the try-function returns false, WorkDate is 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

  1. Create a new company using the DE localization with Contoso demo data enabled.
  2. Confirm the setup completes without the "Document record ID must contain a value in E-Document" error.
  3. Confirm that WorkDate returns to its original value after the demo data run completes, regardless of whether any individual E-Document invoice failed during generation.

Expected behavior

  • New DE company creation with E-Document and Contoso demo data succeeds in v29+.
  • If a Generate() call fails for any reason, WorkDate is restored to its value before demo data generation started, and the original error message is surfaced to the caller.

…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
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Issue #26944 is not valid. Please make sure you link an issue that exists, is open and is approved.

@JesperSchulz

Copy link
Copy Markdown
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 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Integration GitHub request for Integration area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Error on new company with demo data: "‘Document record ID’ must contain a value in ‘E-document’"

2 participants