[FR][Codeunit 10978][CII XML Builder] Add OnAfterBuildCIIDocument event to customize Factur-X XML
Why do you need this change?
We need to customize the Factur-X CII XML generated by the French e-invoicing application to reflect our customers’ actual invoicing and payment conditions.
For example, procedure AddExchangedDocument currently generates the following notes using hardcoded, locked labels:
AAB: early payment discount terms.
PMD: late payment penalties.
PMT: recovery costs.
These fixed texts do not always match the conditions applicable to our customers’ invoices. We need to populate these notes from our configuration or posted document data, while retaining the required subject codes and complying with the applicable Factur-X rules.
More generally, we need an extension point to enrich or correct the generated XML using source document data, including custom fields.
For UBL/Peppol, we have used OnAfterInjectFrenchElements for this type of customization. We need an equivalent extension point in the Factur-X generation flow.
The existing events in codeunit 10978 do not cover this scenario:
OnBeforeAddExchangedDocumentContext only allows replacing the document context generation.
OnAfterAddExchangedDocumentContext is raised before AddExchangedDocument and AddSupplyChainTradeTransaction. At that point, the notes and transaction elements have not yet been generated, so subscribers cannot update them.
A new event after the complete XML document has been built would allow extensions to customize the output while preserving the standard generation logic.
Describe the request
Please add the following integration event to codeunit 10978 “CII XML Builder”, in procedure BuildCIIDocument.
Source file:
src/Apps/FR/EDocument_FR/EReportingFR/app/src/Core/CIIXMLBuilder.Codeunit.al
Proposed event signature
[IntegrationEvent(false, false)]
local procedure OnAfterBuildCIIDocument(
var XmlDoc: XmlDocument;
var EDocument: Record "E-Document";
var SourceDocumentHeader: RecordRef;
var SourceDocumentLines: RecordRef)
begin
end;
Proposed call location
Raise the event immediately after XmlDoc.Add(RootElement) and before the XML is written to TempBlob:
AddExchangedDocumentContext(RootElement, SourceDocumentLines);
AddExchangedDocument(RootElement, EDocument, TypeCode);
AddSupplyChainTradeTransaction(RootElement, EDocument, SourceDocumentHeader, SourceDocumentLines, CompanyInformation);
XmlDoc.Add(RootElement);
OnAfterBuildCIIDocument(XmlDoc, EDocument, SourceDocumentHeader, SourceDocumentLines);
TempBlob.CreateOutStream(OutStr, TextEncoding::UTF8);
XmlDoc.WriteTo(OutStr);
end;
Passing XmlDoc by reference would allow subscribers to update existing elements and insert additional elements before serialization.
The E-Document and source document references provide the context needed to derive customer-specific values and access custom fields. This location covers both invoices and credit memos, since both use BuildCIIDocument.
For our initial scenario, a subscriber would locate the IncludedNote elements under ExchangedDocument and update their Content according to their SubjectCode (AAB, PMD, or PMT).
This proposal does not require an IsHandled parameter or bypass any standard generation logic. Without subscribers, the generated output remains unchanged.
Provide an implementation (optional)
- [ ] I will provide the implementation for this extensibility request
✅ Analysis complete - ready for further processing
Implementation:
Add a new integration event in BuildCIIDocument after the root element is added and before the XML document is written to the temporary blob.
Location in BuildCIIDocument procedure:
AddExchangedDocumentContext(RootElement, SourceDocumentLines);
AddExchangedDocument(RootElement, EDocument, TypeCode);
AddSupplyChainTradeTransaction(RootElement, EDocument, SourceDocumentHeader, SourceDocumentLines, CompanyInformation);
XmlDoc.Add(RootElement);
OnBuildCIIDocumentOnAfterAddRootElement(XmlDoc, EDocument, SourceDocumentHeader, SourceDocumentLines);
TempBlob.CreateOutStream(OutStr, TextEncoding::UTF8);
XmlDoc.WriteTo(OutStr);
Event Publisher (add at the end of the codeunit with other events):
[IntegrationEvent(false, false)]
local procedure OnBuildCIIDocumentOnAfterAddRootElement(var XmlDoc: XmlDocument; var EDocument: Record "E-Document"; var SourceDocumentHeader: RecordRef; var SourceDocumentLines: RecordRef)
begin
end;
File: CIIXMLBuilder.Codeunit.al
[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.
[!TIP] Is the triage result incorrect? Reply with
/not-accurateand briefly explain what was wrong. Your feedback improves future responses.