Add extensibility event while generating FatturaPA DettaglioLinee
Why do you need this change?
This would allow extensions to safely add:
- additional
CodiceArticolovalues; - 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:
NumeroLineaCodiceArticoloDescrizione- 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:
- Adding an additional
CodiceArticolocontaining the internal Business Central Item No., while keeping the standard GTIN mapping.
Example:
<CodiceArticolo>
<CodiceTipo>INTERNO</CodiceTipo>
<CodiceValore>ITEM-001</CodiceValore>
</CodiceArticolo>
- Adding typed
AltriDatiGestionalirecords 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 Bufferwhile that line'sDettaglioLineeelement 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:
- navigate or search the completed
XML Buffer; - identify the correct
DettaglioLineenode for each source Fattura Line; - reopen or manipulate that part of the XML tree;
- 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
Hi @marcus905,
Thank you for your extensibility request. To help us process it efficiently, please update the issue to include the required information.
Missing Information:
- Per-line event justification: Please explain why the requested event must fire once for every exported
DettaglioLineeentry during line processing. - Why loop-external alternatives are insufficient: Please explain why an event before the loop or after the loop would not work for your scenario.
Please update the issue with the missing details. We'll automatically re-analyze once updated.
[!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.
Issue body has been edited with the requested info, thanks!
✅ Analysis complete - ready for further processing
Implementation:
Add a new integration event in PopulateLineData() of Codeunit 12179 "Export FatturaPA Document" after the standard line fields and extended text handling, and before the current DettaglioLinee node is closed.
Location in PopulateLineData() procedure:
end;
TempXMLBuffer.AddNonEmptyElement('PrezzoTotale', FormatAmount(TempFatturaLine.Amount));
TempXMLBuffer.AddNonEmptyElement('AliquotaIVA', FormatAmount(TempFatturaLine."VAT %"));
TempXMLBuffer.AddNonEmptyElement('Natura', TempFatturaLine."VAT Transaction Nature");
if TempFatturaLine.Type <> '' then
PopulateAttachedToLinesExtText(TempFatturaLine);
OnPopulateLineDataOnBeforeCloseLine(TempFatturaLine, TempXMLBuffer);
TempXMLBuffer.GetParent();
end;
Event Publisher (add at the end of the codeunit with other events):
[IntegrationEvent(false, false)]
local procedure OnPopulateLineDataOnBeforeCloseLine(var TempFatturaLine: Record "Fattura Line" temporary; var TempXMLBuffer: Record "XML Buffer" temporary)
begin
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.
With the Italian localization now planned to move to the new E-Documents/SDI framework in 2027 release wave 1, I also wanted to clarify that the requirement here is serializer-independent.
If Export FatturaPA Document / PopulateLineData() remains the serializer behind the new framework, the proposed event is sufficient. If line serialization is being redesigned as part of that work, we would instead need the equivalent extensibility point in the new serializer: once per DettaglioLinee, with access to the current source/Fattura line and to the current line output node/buffer, before that node is closed.
The important contract is the ability to append schema-valid line children such as additional CodiceArticolo and typed AltriDatiGestionali without replacing the standard serializer.
Please recreate your request in BCApps.