Zum Inhalt

Datensatzwerttyp: Codeunit

Mit dem Typ: Codeunit kann ein Wert aus einer Tabelle individuell definiert werden. Programmierte Funktionen, Filter und andere Dinge können dafür verwendet werden.

Beispiel

Wenn der Kunde eine Codeunit zum Zusammenführen von Zeilen oder eine Codeunit für andere Logiken für eine gebuchte Verkaufsrechnung verwendet, dann benötigt man auch eine Codeunit für eDocuments. Andernfalls besteht eine sehr hohe Wahrscheinlichkeit, dass eine ungültige XML-Datei für XInvoice und ZUGFeRD-Formate erstellt wird.

In der Beispiel-Codeunit gibt die Methode GETFUNCTION die Parameterliste für die Datenwertkonfiguration zurück.

Info

Diese Codeunit muss innerhalb einer benutzerdefinierten Erweiterung implementiert werden.

AL
codeunit 50000 "SIM_XSD Custom Data Value"
{
    TableNo = "SIM_XSD Data Value";

    trigger OnRun()
    var
        LocalRecordSalesInvoiceLine: Record "Sales Invoice Line";
        LocalRecordPurchInvLine: Record "Purch. Inv. Line";
        LocalRecordSIMXSDLinkedData: Record "SIM_XSD Linked Data";
        LocalRecordSIMXSDLinkedDataLine: Record "SIM_XSD Linked Data Line";
        LocalRecordRef: RecordRef;
        LocalParamText: Text;
    begin
        if Rec."Codeunit Function" = '' then
            LocalParamText := 'GETFUNCTIONS'
        else
            LocalParamText := Rec."Codeunit Function";

        case LocalParamText of
            'GETFUNCTIONS':
                Rec."Function List" := 'SalesInvoiceLine_CAT,PurchInvLine_CAT';
            'SalesInvoiceLine_CAT':
                begin
                    if not LocalRecordRef.Get(Rec."Codeunit Record ID") then
                        Error('Datensatz existiert nicht.');

                    if not LocalRecordSIMXSDLinkedData.Get('CATEGORY') then
                        Error('Verknüpfte Daten existieren nicht.');

                    if LocalRecordRef.Number <> 113 then
                        Error('Falsche Tabelle');

                    LocalRecordRef.SetTable(LocalRecordSalesInvoiceLine);

                    if LocalRecordSalesInvoiceLine."VAT Bus. Posting Group" = 'NICHTSTB' then begin
                        Rec."Function Return Value" := 'E';
                        exit;
                    end;

                    if LocalRecordSIMXSDLinkedDataLine.Get(LocalRecordSIMXSDLinkedData.Code, LocalRecordSalesInvoiceLine."VAT Prod. Posting Group") then begin
                        Rec."Function Return Value" := LocalRecordSIMXSDLinkedDataLine."New Value";
                        exit;
                    end;

                    Rec."Function Return Value" := '';
                end;
            'PurchInvLine_CAT':
                begin
                    if not LocalRecordRef.Get(Rec."Codeunit Record ID") then
                        Error('Datensatz existiert nicht.');

                    if not LocalRecordSIMXSDLinkedData.Get('CATEGORY') then
                        Error('Verknüpfte Daten existieren nicht.');

                    if LocalRecordRef.Number <> 123 then
                        Error('Falsche Tabelle');

                    LocalRecordRef.SetTable(LocalRecordPurchInvLine);

                    if LocalRecordPurchInvLine."VAT Bus. Posting Group" = 'NICHTSTB' then begin
                        Rec."Function Return Value" := 'E';
                        exit;
                    end;

                    if LocalRecordSIMXSDLinkedDataLine.Get(LocalRecordSIMXSDLinkedData.Code, LocalRecordPurchInvLine."VAT Prod. Posting Group") then begin
                        Rec."Function Return Value" := LocalRecordSIMXSDLinkedDataLine."New Value";
                        exit;
                    end;

                    Rec."Function Return Value" := '';
                end;
        end;
    end;
}

Siehe auch