microsoft / microsoft/ALAppExtensions

Add extensibility event while generating FatturaPA DettaglioLinee

Open
#30,405 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Why do you need this change?

This would allow extensions to safely add:

  • additional CodiceArticolo values;
  • typed AltriDatiGestionali;
  • other valid future FatturaPA line-level elements;

without:

  • duplicating the full FatturaPA serializer;
  • post-processing the entire generated XML;
  • replacing standard Microsoft behavior.

It would also make these customizations much more upgrade-safe and compatible with Business Central SaaS.

Describe the request

We would like to request an additional extensibility point in the Italian FatturaPA export logic, specifically while codeunit 12179 "Export FatturaPA Document" is generating each DettaglioLinee node.

At the moment, PopulateLineData() builds the complete XML representation of a FatturaPA document line, including elements such as:

  • NumeroLinea
  • CodiceArticolo
  • Descrizione
  • quantity / unit price
  • discounts
  • VAT information
  • AltriDatiGestionali

However, PopulateLineData() is local and there is currently no integration event that allows an extension to append additional valid XML elements to the current DettaglioLinee node.

This limits scenarios where an extension needs to add valid FatturaPA line metadata without replacing or post-processing the complete XML document.

Use case

We are implementing additional FatturaPA functionality in a Business Central SaaS extension.

Examples include:

  1. Adding an additional CodiceArticolo containing the internal Business Central Item No., while keeping the standard GTIN mapping.

Example:

<CodiceArticolo>
    <CodiceTipo>INTERNO</CodiceTipo>
    <CodiceValore>ITEM-001</CodiceValore>
</CodiceArticolo>
  1. Adding typed AltriDatiGestionali records associated with a sales line.

For example:

<AltriDatiGestionali>
    <TipoDato>LOTTO</TipoDato>
    <RiferimentoTesto>A19</RiferimentoTesto>
</AltriDatiGestionali>

or:

<AltriDatiGestionali>
    <TipoDato>PESO</TipoDato>
    <RiferimentoNumero>12.50</RiferimentoNumero>
</AltriDatiGestionali>

or:

<AltriDatiGestionali>
    <TipoDato>DATA</TipoDato>
    <RiferimentoData>2026-08-07</RiferimentoData>
</AltriDatiGestionali>

The existing extended-text extensibility in Fattura Doc. Helper is useful for textual content, but it is not sufficient for this scenario because AltriDatiGestionali supports different typed elements such as RiferimentoTesto, RiferimentoNumero, and RiferimentoData.

Requested extensibility point

A simple additive integration event raised near the end of PopulateLineData(), after the standard Microsoft fields have been written but before the current DettaglioLinee XML node is closed, would solve this cleanly.

For example:

[IntegrationEvent(false, false)]
local procedure OnPopulateLineDataBeforeCloseLine(
    var TempFatturaLine: Record "Fattura Line" temporary;
    var TempXMLBuffer: Record "XML Buffer" temporary)
begin
end;

Conceptually:

local procedure PopulateLineData(...)
begin
    TempXMLBuffer.AddGroupElement('DettaglioLinee');

    // Standard Microsoft serialization
    // NumeroLinea
    // CodiceArticolo
    // Descrizione
    // Quantita
    // PrezzoUnitario
    // ScontoMaggiorazione
    // PrezzoTotale
    // AliquotaIVA
    // Natura
    // existing AltriDatiGestionali

    OnPopulateLineDataBeforeCloseLine(
        TempFatturaLine,
        TempXMLBuffer);

    TempXMLBuffer.GetParent();
end;

We do not require an IsHandled parameter because the goal is not to replace Microsoft's standard line serialization. We only need the ability to append additional schema-valid child elements to the existing DettaglioLinee.

Additional clarification: why the event must be raised per line

The requested event needs to run once for each exported DettaglioLinee because the extension data is associated with a specific invoice line and must be written as child elements of that same DettaglioLinee XML node.

For example, an invoice can contain:

Line 1 - Item A
    Internal Item No. = ITEM-A
    LOTTO = A19

Line 2 - Item B
    Internal Item No. = ITEM-B
    PESO = 12.50

The required XML is therefore structurally line-specific:

<DettaglioLinee>
    <NumeroLinea>1</NumeroLinea>

    <CodiceArticolo>
        <CodiceTipo>INTERNO</CodiceTipo>
        <CodiceValore>ITEM-A</CodiceValore>
    </CodiceArticolo>

    <AltriDatiGestionali>
        <TipoDato>LOTTO</TipoDato>
        <RiferimentoTesto>A19</RiferimentoTesto>
    </AltriDatiGestionali>
</DettaglioLinee>

<DettaglioLinee>
    <NumeroLinea>2</NumeroLinea>

    <CodiceArticolo>
        <CodiceTipo>INTERNO</CodiceTipo>
        <CodiceValore>ITEM-B</CodiceValore>
    </CodiceArticolo>

    <AltriDatiGestionali>
        <TipoDato>PESO</TipoDato>
        <RiferimentoNumero>12.50</RiferimentoNumero>
    </AltriDatiGestionali>
</DettaglioLinee>

The extension therefore needs both:

  • the current Fattura Line, so it can identify which source/document line is being serialized;
  • the current XML Buffer while that line's DettaglioLinee element is still open.
Why an event before the line loop is not sufficient

An event before the loop would run before any individual DettaglioLinee node has been created.

At that point the extension could potentially inspect the complete temporary Fattura Line dataset, but it could not append XML elements to the corresponding line because there is no current DettaglioLinee XML node yet.

The extension would therefore have to duplicate Microsoft's complete line serialization loop in order to create and associate the custom nodes correctly, which is exactly what this extensibility request is intended to avoid.

Why an event after the line loop is not sufficient

An event after the loop would run after all DettaglioLinee elements have already been generated and closed.

The extension would then need to:

  1. navigate or search the completed XML Buffer;
  2. identify the correct DettaglioLinee node for each source Fattura Line;
  3. reopen or manipulate that part of the XML tree;
  4. insert the additional nodes in the correct schema position.

This is significantly more fragile than adding the nodes while Microsoft is already serializing the corresponding line.

It also creates additional coupling to:

  • the internal structure of XML Buffer;
  • how Microsoft numbers or identifies line elements;
  • the exact order in which the FatturaPA document is generated.

A per-line event avoids this entirely because the extension is invoked at the point where Microsoft already knows the current line and already has the correct DettaglioLinee node open.

Why this is preferable to replacing the line serialization

The requested event is intentionally additive and does not require IsHandled.

Microsoft would continue to own all standard serialization logic.

The extension would only append additional schema-valid children for the current line, for example additional CodiceArticolo or typed AltriDatiGestionali.

This keeps the customization:

  • upgrade-safe;
  • compatible with standard Microsoft output;
  • limited to the specific additional data required by the extension.

For this reason, raising the event once per exported DettaglioLinee, immediately before the current line element is closed, is the narrowest and least invasive extensibility point for this scenario.

Environment
  • Business Central Cloud / SaaS
  • Italian localization
  • Version 28.x

Thank you for considering this extensibility request.

Internal work item: AB#646226

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 in codeunit 12179 "Export FatturaPA Document" and locate the local PopulateLineData() procedure. Verify how the current Fattura Line and XML Buffer are available while each DettaglioLinee node is open. Done means an additive per-line extensibility point exists before the node closes, allowing valid additional line elements without replacing standard serialization.

Written by the indexing model from the issue text.

Assessment

Tech stack
xml
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.