Skip to content
This repository was archived by the owner on Oct 19, 2026. It is now read-only.
This repository was archived by the owner on Oct 19, 2026. It is now read-only.

Make FatturaPA XML generation reusable from cloud extensions #30404

Closed

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

Activity

  1. added
    Integration
    request-for-external
    on Aug 7, 2026
  2. github-actions commented on Aug 7, 2026

    @github-actions
    Contributor

    ✅ Analysis complete - ready for further processing


    Implementation:

    Expose a public cloud-safe buffer-to-XML entry point in codeunit 12179 "Export FatturaPA Document" by making GenerateXMLFile available for extensions so temporary Fattura Header and Fattura Line buffers can be serialized through the standard Microsoft FatturaPA XML generation logic.

    Current code:

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

    Proposed change:

    procedure GenerateXMLFile(var TempBlob: Codeunit "Temp Blob"; var TempFatturaLine: Record "Fattura Line" temporary; TempFatturaHeader: Record "Fattura Header" temporary; ClientFileName: Text[250])
    var
        ExportFatturaPADocument: Codeunit "Export FatturaPA Document";
    begin
        Session.LogMessage('0000CQ9', GenerateXMLMsg, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', FatturaTok);
    
        CompanyInformation.Get();
        BindSubscription(ExportFatturaPADocument);
    
        if not TryCreateFatturaElettronicaHeader(TempFatturaHeader) then begin
            Session.LogMessage('0000CQA', StrSubstNo(HeaderErrMsg, GetLastErrorText()), Verbosity::Error, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', FatturaTok);
            Error(GetLastErrorText());
        end;

    File: ExportFatturaPADocument.Codeunit.al

    Note

    Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.

    Tip

    Not accurate? Reply with /not-accurate (optional: add a short explanation). Your feedback improves future responses.

  3. marcus905 commented on Sep 14, 2026

    @marcus905
    Author

    Microsoft now lists "Updated electronic invoicing with new e-documents framework (SDI)" for Italy in 2027 release wave 1.

    In light of that planned migration, I wanted to clarify that this request does not specifically depend on codeunit 12179 remaining the long-term FatturaPA serializer. The requirement is to have a supported SaaS API that can generate the same standard outbound FatturaPA payload that the E-Document/SDI implementation will send, from extension-prepared document data, without consuming a transmission/progressive number or requiring the document to be posted.

    If the Italian implementation is being moved behind the E-Document framework, an equivalent public “prepare/serialize outbound FatturaPA payload” API in that new architecture would satisfy the request and would actually be preferable to exposing a legacy method that will later be superseded. The primary use case remains pre-post preview and validation using Microsoft's authoritative serializer.

  4. darjoo commented on Oct 5, 2026

    @darjoo
    Contributor

    Please recreate your request in BCApps.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Integrationrequest-for-external

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions