Skip to content

Data Value Type: Codeunit

With the Type: Codeunit a value from a table can be defined individually. Programmed functions, filters and other things can be used for this.

Returning codeunit text longer than 250 characters

This requires installed CORE and, for eDocuments, eDocuments versions that include the BLOB return methods below. The methods are not available in older symbols; update the app dependencies and symbols of your custom extension before using them.

For an eDocuments data value of type Codeunit, call SetFunctionReturnValueText on the SIM_XSD Data Value buffer passed to your codeunit. eDocuments stores the result in Function Return Value Blob and reads it with GetFunctionReturnValueText before applying the configured data value formatting.

Rec.SetFunctionReturnValueText(LocalResultText);

LocalResultText must be a Text variable without a fixed length and contain the complete calculated result. Do not shorten it with CopyStr or pass it through a Text[250] variable first. Call the setter after calculating the result; no Insert, Modify, or manual BLOB stream handling is required.

The BLOB result takes precedence when present. Without a BLOB result, the engine still reads the existing 250-character return field. Existing codeunits and the short-text examples below therefore remain supported. Both setters clear the legacy text field, so an explicitly empty result does not fall back to an earlier short value. UTF-8 text and line breaks are preserved.

The new return channel does not remove limits imposed by the receiving field or document format. Check data value formatting for a configured COPYSTR operation and validate the output against the actual XML schema and document profile. For example, verify the complete header reference in BuyerOrderReferencedDocument using a result longer than 250 characters, Unicode characters, line breaks, and an empty result.

Example

When the customer uses a code unit for merging lines or a codeunit for other logics for a posted sales invoice, then you also need a codeunit for eDocuments. Otherwise, there is a very high chance that an invalid XML file will be created for XInvoice and ZUGFeRD formats.

In the sample codeunit, the GETFUNCTION method returns the parameter list for the data value configuration.

Info

This codeunit must be implemented within a custom extension.

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

See also