Skip to content

E-Document: restore default file extension fallback in ExportDataStorage - #9851

Draft
Groenbech96 with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-exported-e-document-files
Draft

E-Document: restore default file extension fallback in ExportDataStorage#9851
Groenbech96 with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-exported-e-document-files

Conversation

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Exporting E-Document files for any format without a dedicated OnBeforeExportDataStorage subscriber (German XRechnung, PEPPOL BIS 3.0 DE, FR Peppol BIS 3.0, DK OIOUBL, ES Factura-E/Verifactu, APAC PINT A-NZ, W1 Data Exchange, custom formats) produced a downloaded file with no extension — a regression from scoping the PEPPOL .xml subscriber to only "PEPPOL BIS 3.0".

Fix

  • E-Document Log.ExportDataStorage() now falls back to E-Document Service.GetDefaultFileExtension() when no subscriber has already set an extension on the file name after OnBeforeExportDataStorage runs.
  • Formats with their own extension logic (ZUGFeRD, Factur-X, PEPPOL BIS 3.0) are unaffected — the fallback only applies when the file name still has no extension.
  • Default extension remains .xml, still overridable per-service via OnAfterGetDefaultFileExtension.
OnBeforeExportDataStorage(Rec, FileName);

if FileManagement.GetExtension(FileName) = '' then
    if EDocumentService.Get("Service Code") then
        FileName += EDocumentService.GetDefaultFileExtension();

DownloadFromStream(InStr, '', '', '', FileName);

Test

  • Added a regression test exporting a log entry for a format with no dedicated subscriber ("Data Exchange"), asserting the downloaded file name ends in .xml.

Copilot AI changed the title [WIP] Fix exported e-document files lacking file extension for German formats E-Document: restore default file extension fallback in ExportDataStorage Jul 30, 2026
Copilot AI requested a review from Groenbech96 July 30, 2026 11:42
@github-actions github-actions Bot added needs-approval Workflow runs require maintainer approval to start AL: Apps (W1) Add-on apps for W1 labels Jul 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Could not find a linked ADO work item. Please link one by using the pattern 'AB#' followed by the relevant work item number. You may use the 'Fixes' keyword to automatically resolve the work item when the pull request is merged. E.g. 'Fixes AB#1234'

@github-actions github-actions Bot removed the needs-approval Workflow runs require maintainer approval to start label Jul 31, 2026
@Groenbech96

Copy link
Copy Markdown
Contributor

@copilot Fix the issues.

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Fix the issues.

Found it — the CI failures were caused by two unused using directives in the new test codeunit (System.TestLibraries.Utilities and System.Utilities), which triggered AL0792 compiler errors. That broke compilation of E-Document Core Tests, cascading into failures across nearly every unrelated workspace build (W1, FR, DE, GB, etc.). Removed the unused directives in 6c99fc1.

@github-actions github-actions Bot added needs-approval Workflow runs require maintainer approval to start and removed needs-approval Workflow runs require maintainer approval to start labels Jul 31, 2026
Resolves 'Unit Tests (*) (IntegrationTests)' in Pull Request Build:
"Function ExportDataStorageFallsBackToDefaultFileExtension Assert.IsTrue failed.
Expected the exported file to fall back to the default file extension."

ExportDataStorage called the AL built-in DownloadFromStream directly, which does
not raise Codeunit "File Management"::OnBeforeDownloadFromStreamHandler. The test
library "Library - File Mgt Handler" only subscribes to that event, so it never
captured the file name and GetDownloadFromSreamToFileName() returned '' - making
the new test fail regardless of whether the extension fallback works.

Routing the download through FileManagement.DownloadFromStreamHandler keeps the
same runtime behaviour (it calls DownloadFromStream) and makes the file name
observable to the standard test hook.

[bcapps-fix-loop attempt 1]

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Groenbech96

Copy link
Copy Markdown
Contributor

CI triage for run 30622841084 (attempt 2) — all 26 Unit Tests (*) (IntegrationTests) jobs failed with the same three assertions in every country. One is ours, two are not.

1. Real / change-related — fixed in d9d2d0f
ExportDataStorageFallsBackToDefaultFileExtension: Assert.IsTrue failed. Expected the exported file to fall back to the default file extension.

Root cause is the test hook, not the fallback logic. E-Document Log.ExportDataStorage() called the AL built-in DownloadFromStream(...) directly. Library - File Mgt Handler (codeunit 131106) only subscribes to Codeunit "File Management"::OnBeforeDownloadFromStreamHandler, which is raised only by FileManagement.DownloadFromStreamHandler(...). So the subscriber never ran, GetDownloadFromSreamToFileName() returned '', and ''.EndsWith('.xml') was always false — the test could never pass, whether or not the .xml fallback worked.

Fix: route the export through FileManagement.DownloadFromStreamHandler(InStr, '', '', '', FileName). Same runtime behaviour (it calls DownloadFromStream internally) and it is the standard testable wrapper used by ~20 other export paths in BaseApp.

2. Not this PR — needs a separate look

  • UnitTestCalcPriceUsesCurrentWorkDateThe record in table Price List Line already exists (Price List Code='GU00000015')
  • Modify_ClearSourceTableNo_ShouldError (codeunit 139955) — An error was expected inside an ASSERTERROR statement

Both are unrelated to E-Documents and reproduce in all 26 country jobs. Run 30614237197 (07:51 UTC today) had 22/22 IntegrationTests green, and main gained #9850 (Contract Price Update) and #8959 between that run and this one — so these look like main-side regressions, not something to patch here. This PR will stay red until they are resolved on main.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[E-Document] Exported e-document files have no file extension for German formats (XRechnung, PEPPOL BIS 3.0 DE) and other non-W1-PEPPOL formats

2 participants