microsoft / microsoft/ALAppExtensions

Make FatturaPA XML generation reusable from cloud extensions

Open
#30,404 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Integration request-for-external
Dominant language
AL
Stars
988
Forks
692
Avg merge
49m
Merged PRs (30d)
1

Description

Why do you need this change?

We are implementing a pre-posting FatturaPA preview for Sales Invoices / Credit Memos in Business Central Cloud.

The goal is to let a user review the exact FatturaPA XML, and render it with the official Agenzia delle Entrate XSLT, before posting the document.

Describe the request

Please expose a cloud-safe API boundary in codeunit 12179 "Export FatturaPA Document" that allows an extension to generate the standard Microsoft FatturaPA XML from already prepared temporary "Fattura Header" and "Fattura Line" buffers.

The existing procedure is very close to what is needed:

[Scope('OnPrem')]
procedure GenerateXMLFile(
    var TempBlob: Codeunit "Temp Blob";
    var TempFatturaLine: Record "Fattura Line" temporary;
    TempFatturaHeader: Record "Fattura Header" temporary;
    ClientFileName: Text[250])

For a SaaS/Cloud extension this procedure cannot be used because it is scoped OnPrem.

Business scenario

We are implementing a pre-posting FatturaPA preview for Sales Invoices / Credit Memos in Business Central Cloud.

The goal is to let a user review the exact FatturaPA XML, and render it with the official Agenzia delle Entrate XSLT, before posting the document.

It is important that the preview uses Microsoft's standard FatturaPA serializer rather than a duplicated custom XML writer, so that:

  • XML element ordering and formatting remain identical to the standard exporter;
  • future Business Central updates to the FatturaPA implementation are inherited automatically;
  • existing integration events such as OnBeforePopulatePaymentData, OnBeforePopulateOrderData, OnTryCreateFatturaElettronicaBodyOnAfterTempFatturaLineSetFiltersForDocument, and OnAfterCreateBlobXML continue to behave consistently;
  • extensions do not have to clone codeunit 12179 simply to obtain an XML stream.
Why running codeunit 12179 directly is not suitable for preview

Running Export FatturaPA Document through its normal OnRun path is not a good substitute because it first calls Fattura Doc. Helper.CollectDocumentInformation on a posted source document.

For a pre-posting preview:

  1. the source is an unposted Sales Header / Sales Line;
  2. VAT summaries and payment instalments need to be prepared from the current unposted document state rather than posted VAT Entry / Cust. Ledger Entry records;
  3. Fattura Doc. Helper currently obtains a new FatturaPA progressive number through GetNextProgressiveNo(), so invoking the full standard collection path for every preview can consume real progressive numbers.

The extension can prepare suitable temporary Fattura Header / Fattura Line buffers itself while reusing the existing helper and its events where possible.

What is missing is a supported cloud API that hands those buffers to the same Microsoft XML generation logic used by the posted export.

Requested solution

Preferred option: make GenerateXMLFile available to cloud extensions by removing [Scope('OnPrem')], provided there are no technical reasons preventing that.

Alternatively, please add a new public cloud-safe procedure with equivalent semantics, for example:

procedure GenerateXMLFromBuffers(
    var TempBlob: Codeunit "Temp Blob";
    var TempFatturaLine: Record "Fattura Line" temporary;
    TempFatturaHeader: Record "Fattura Header" temporary;
    ClientFileName: Text[250])

The important requirement is that this procedure invokes the existing Microsoft FatturaPA serializer rather than exposing or requiring a second implementation.

Benefits beyond preview

A reusable buffer-to-XML API would also support:

  • pre-posting validation tools;
  • test automation comparing expected FatturaPA output;
  • controlled previews for custom sales document workflows;
  • extensions that add additional structured FatturaPA data while remaining aligned with Microsoft's current schema implementation.
Target

Business Central Cloud / SaaS, current Italian localization (BC 28.x).

Internal work item: AB#646218

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting codeunit 12179 "Export FatturaPA Document", especially the OnPrem GenerateXMLFile procedure and the normal OnRun path. Verify how the temporary "Fattura Header" and "Fattura Line" buffers reach the existing serializer and whether a cloud-safe boundary is technically possible. Done means extensions can invoke the same XML generation logic from prepared buffers without duplicating the serializer.

Written by the indexing model from the issue text.

Assessment

Domain
api, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.