Aller au contenu

Type de valeur de données : Codeunit

Avec le Type : Codeunit, une valeur d'une table peut être définie individuellement. Des fonctions programmées, des filtres et d'autres éléments peuvent être utilisés à cet effet.

Exemple

Lorsque le client utilise une codeunit pour fusionner des lignes ou une codeunit pour d'autres logiques pour une facture de vente publiée, il faut également une codeunit pour les eDocuments. Sinon, il y a un très grand risque qu'un fichier XML invalide soit créé pour les formats XInvoice et ZUGFeRD.

Dans la codeunit d'exemple, la méthode GETFUNCTION renvoie la liste des paramètres pour la configuration de la valeur de données.

Info

Cette codeunit doit être implémentée dans une extension personnalisée.

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('L\'enregistrement n\'existe pas.');

                    if not LocalRecordSIMXSDLinkedData.Get('CATEGORY') then
                        Error('Les données liées n\'existent pas.');

                    if LocalRecordRef.Number <> 113 then
                        Error('Mauvaise table');

                    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('L\'enregistrement n\'existe pas.');

                    if not LocalRecordSIMXSDLinkedData.Get('CATEGORY') then
                        Error('Les données liées n\'existent pas.');

                    if LocalRecordRef.Number <> 123 then
                        Error('Mauvaise table');

                    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;
}

Voir aussi