Skip to content

Make FatturaPA XML generation reusable from cloud extensions #30404

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    IntegrationGitHub request for Integration arearequest-for-externalRequest for exposing a function for extension development

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions