ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[Extensibility Request] Support for additional ZUGFeRD document type codes in Codeunit 13919

Open ADO-BST opened this issue 6 months ago • 3 comments

Why do you need this change?

Additional to #29656

Description

We need an extension point in Codeunit 13919 "Import ZUGFeRD Document" in the ParseCompleteInfo procedure, similar to the existing OnParseBasicInfoOnBeforeDocumentTypeCheck pattern that already allows us to influence the document type validation during basic parsing.

Currently, a second document type check inside ParseCompleteInfo can reintroduce issues that have already been handled in OnParseBasicInfoOnBeforeDocumentTypeCheck. We need a way to intercept and optionally override/skip this logic during the complete parsing phase.

What we want to address

  • Avoid duplicate or conflicting document type validation in ParseCompleteInfo.
  • Allow partners to control or bypass the standard logic in ParseCompleteInfo when necessary, in the same way this is already possible in ParseBasicInfo.

Requested change (single object)

In Codeunit 13919 "Import ZUGFeRD Document", in ParseCompleteInfo:

  • Introduce a CompleteInfoParsed: Boolean flag.
  • Add a new integration event, e.g. OnParseCompleteInfoOnBeforeDocumentTypeCheck, that:
    • Exposes DocumentType, EDocument, TempXMLBuffer, DocumentNamespace, CrossIndustryInvoiceLbl, PurchaseHeader, and PurchaseLine.
    • Allows the subscriber to set CompleteInfoParsed := true to skip the standard case logic.

This will align the behavior of ParseCompleteInfo with ParseBasicInfo and allow us to prevent the problematic re-validation during complete parsing.

Describe the request

In Codeunit 13919 "Import ZUGFeRD Document", the current implementation (around line 57) only subscribes to/uses OnParseBasicInfoOnBeforeDocumentTypeCheck, but not to an equivalent in ParseCompleteInfo.
However, a second validation in ParseCompleteInfo causes issues that should already be handled by OnParseBasicInfoOnBeforeDocumentTypeCheck.

Therefore, we urgently need a solution that allows us to influence the behavior in ParseCompleteInfo in the same way. An example solution would be to extend ParseCompleteInfo as follows:

procedure ParseCompleteInfo(var EDocument: Record "E-Document"; var PurchaseHeader: Record "Purchase Header" temporary; var PurchaseLine: Record "Purchase Line" temporary; var TempBlob: Codeunit "Temp Blob")
var
    TempXMLBuffer: Record "XML Buffer" temporary;
    DocumentType: Text;
    DocumentNamespace: Text;
    PdfAttachmentStream: InStream;
    CompleteInfoParsed: Boolean;
    DocumentElementLbl: Label '%1:%2', Comment = '%1 = Namespace, %2 = Document', Locked = true;
    CrossIndustryInvoiceLbl: Label 'CrossIndustryInvoice', Locked = true;
begin
    FeatureTelemetry.LogUsage('0000EXS', FeatureNameTok, ContinueEventNameTok);
    TempXMLBuffer.DeleteAll();
    TempBlob.CreateInStream(PdfAttachmentStream);
    TempXMLBuffer.LoadFromStream(PdfAttachmentStream);
    EDocument.Direction := EDocument.Direction::Incoming;
    DocumentNamespace := GetNamespace(TempXMLBuffer);
    DocumentType := GetDocumentType(TempXMLBuffer, DocumentNamespace);

    PurchaseHeader."Buy-from Vendor No." := EDocument."Bill-to/Pay-to No.";
    PurchaseHeader."Currency Code" := EDocument."Currency Code";

    CompleteInfoParsed := false;
    OnParseCompleteInfoOnBeforeDocumentTypeCheck(DocumentType, EDocument, TempXMLBuffer, DocumentNamespace, CrossIndustryInvoiceLbl, PurchaseHeader, PurchaseLine);
    if not CompleteInfoParsed then
        case UpperCase(DocumentType) of
            '380', '384', '751', '877':
                if DocumentNamespace <> '' then
                    CreateInvoice(EDocument, PurchaseHeader, PurchaseLine, TempXMLBuffer, StrSubstNo(DocumentElementLbl, DocumentNamespace, CrossIndustryInvoiceLbl))
                else
                    CreateInvoice(EDocument, PurchaseHeader, PurchaseLine, TempXMLBuffer, CrossIndustryInvoiceLbl);
            '381', '261':
                if DocumentNamespace <> '' then
                    CreateCreditMemo(EDocument, PurchaseHeader, PurchaseLine, TempXMLBuffer, StrSubstNo(DocumentElementLbl, DocumentNamespace, CrossIndustryInvoiceLbl))
                else
                    CreateCreditMemo(EDocument, PurchaseHeader, PurchaseLine, TempXMLBuffer, CrossIndustryInvoiceLbl);
        end;
    FeatureTelemetry.LogUsage('0000WXJ', FeatureNameTok, StrSubstNo(EndEventNameTok, EDocument."Document Type", EDocument."Incoming E-Document No."));
end;
<------>
    [IntegrationEvent(false, false)]
    internal procedure OnParseCompleteInfoOnBeforeDocumentTypeCheck(var DocumentType: Text; var EDocument: Record "E-Document"; var TempXMLBuffer: Record "XML Buffer" temporary; DocumentNamespace: Text; CrossIndustryInvoiceLbl: Text; var PurchaseHeader: Record "Purchase Header" temporary; var PurchaseLine: Record "Purchase Line" temporary; var CompleteInfoParsed: Boolean)
    begin
    end;

Internal work item: AB#636238

ADO-BST avatar May 20 '26 14:05 ADO-BST

✅ Analysis complete - approved for implementation


Implementation:

Add a new integration event in the ParseCompleteInfo procedure of Codeunit 13919 "Import ZUGFeRD Document" before the document type check, with CompleteInfoParsed (IsHandled) pattern.

Location in ParseCompleteInfo procedure (around line 82):

    PurchaseHeader."Buy-from Vendor No." := EDocument."Bill-to/Pay-to No.";
    PurchaseHeader."Currency Code" := EDocument."Currency Code";

    CompleteInfoParsed := false;
    OnParseCompleteInfoOnBeforeDocumentTypeCheck(DocumentType, EDocument, TempXMLBuffer, DocumentNamespace, CrossIndustryInvoiceLbl, PurchaseHeader, PurchaseLine, CompleteInfoParsed);  // <-- New event
    if not CompleteInfoParsed then
        case UpperCase(DocumentType) of
            '380', '384', '751', '877':
                if DocumentNamespace <> '' then
                    CreateInvoice(EDocument, PurchaseHeader, PurchaseLine, TempXMLBuffer, StrSubstNo(DocumentElementLbl, DocumentNamespace, CrossIndustryInvoiceLbl))
                else
                    CreateInvoice(EDocument, PurchaseHeader, PurchaseLine, TempXMLBuffer, CrossIndustryInvoiceLbl);
            '381', '261':
                if DocumentNamespace <> '' then
                    CreateCreditMemo(EDocument, PurchaseHeader, PurchaseLine, TempXMLBuffer, StrSubstNo(DocumentElementLbl, DocumentNamespace, CrossIndustryInvoiceLbl))
                else
                    CreateCreditMemo(EDocument, PurchaseHeader, PurchaseLine, TempXMLBuffer, CrossIndustryInvoiceLbl);
        end;
    FeatureTelemetry.LogUsage('0000WXJ', FeatureNameTok, StrSubstNo(EndEventNameTok, EDocument."Document Type", EDocument."Incoming E-Document No."));

Event Publisher (add at the end of the codeunit with other events):

[IntegrationEvent(false, false)]
internal procedure OnParseCompleteInfoOnBeforeDocumentTypeCheck(var DocumentType: Text; var EDocument: Record "E-Document"; var TempXMLBuffer: Record "XML Buffer" temporary; DocumentNamespace: Text; CrossIndustryInvoiceLbl: Text; var TempPurchaseHeader: Record "Purchase Header" temporary; var TempPurchaseLine: Record "Purchase Line" temporary; var CompleteInfoParsed: Boolean)
begin
end;

File: ImportZUGFeRDDocument.Codeunit.al

AleksandricMarko avatar May 21 '26 08:05 AleksandricMarko

Is there any news yet about the implementation?

ADO-BST avatar Jul 07 '26 11:07 ADO-BST

Issue fixed 2nd of June. Automation failed to close this issue.

JesperSchulz avatar Sep 01 '26 14:09 JesperSchulz