Senden der Datei über eine benutzerdefinierte Codeunit
In dieser Dokumentation erstellen wir eine Beispiel-Codeunit, die die Integration von externem Code ermöglicht und es Document Dispatch ermöglicht, Dateien zu senden, die über eine Codeunit empfangen wurden.
Info
Diese benutzerdefinierte Codeunit muss in einer benutzerdefinierten Erweiterung implementiert werden. Bitte beachten Sie die Kommentare in der Beispiel-Codeunit.
Folgende Voraussetzungen müssen erfüllt sein:
Die Document Dispatch-Erweiterung muss lizenziert werden.
Auf die Erweiterung Document Dispatch muss in der benutzerdefinierten Erweiterung verwiesen werden.
Document Dispatch Custom Codeunit:
| AL |
|---|
| codeunit 50000 "Document Dispatch Custom Codeunit"
{
TableNo = "SIM_EDS Record Attachment";
Permissions = tabledata "SIM_EDS Queue Line" = RIM;
trigger OnRun()
begin
CreateCustomAttatchments(Rec)
end;
var
GlobalCodeunitSIMEDSSI: Codeunit "SIM_EDS SI";
procedure CreateCustomAttatchments(ParamRecordSIMEDSRecordAttachment: Record "SIM_EDS Record Attachment")
var
LocalRecordSIMEDSQueueLine: Record "SIM_EDS Queue Line";
LocalCodeunitBase64Convert: Codeunit "Base64 Convert";
LocalCodeunitSIMCORERecordRef: Codeunit "SIM_CORE RecordRef";
LocalCodeunitSIMCOREDataMapping: Codeunit "SIM_CORE Data Mapping";
LocalCodeunitSIMCOREText: Codeunit "SIM_CORE Text";
LocalRecordId: RecordId;
LocalRRecordRef: RecordRef;
LocalMappingRecordRef: RecordRef;
LocalResultRecordRef: RecordRef;
LocalOOutStream: OutStream;
LocalFileBase64StringText: Text;
LocalFilenameTempText: Text;
LocalLineNoInteger: Integer;
LocalDoExportBoolean: Boolean;
begin
// Prüfen, ob die Codeunit eingerichtet ist
if GlobalCodeunitSIMEDSSI.GetCodeunitRecID() = '' then exit;
if GlobalCodeunitSIMEDSSI.GetCodeunitQueueID() = 0 then exit;
if not Evaluate(LocalRecordId, GlobalCodeunitSIMEDSSI.GetCodeunitRecID()) then exit;
if not LocalRRecordRef.Get(LocalRecordId) then exit;
// Get the Queue Line No. from the Document Dispatch SI codeunit
LocalLineNoInteger := GlobalCodeunitSIMEDSSI.GetCodeunitQueueLineNo();
// Abrufen der Datensatzreferenz aus dem Attachment Record
if ParamRecordSIMEDSRecordAttachment."Dynamic Mapping Code" = '' then
LocalCodeunitSIMCORERecordRef.FilterRecRefByKey(LocalRRecordRef, LocalResultRecordRef)
else begin
LocalCodeunitSIMCORERecordRef.FilterRecRefByKey(LocalRRecordRef, LocalMappingRecordRef);
LocalCodeunitSIMCOREDataMapping.GetRecordFromMappingHeader(
ParamRecordSIMEDSRecordAttachment."Dynamic Mapping Code",
LocalMappingRecordRef,
LocalResultRecordRef
);
LocalMappingRecordRef.Close();
end;
// Durch die Ergebnisdatensätze iterieren
if LocalResultRecordRef.FindSet() then
repeat
LocalDoExportBoolean := false;
// Logik zur Bestimmung, ob der Datensatz exportiert werden soll
LocalDoExportBoolean := true;
if LocalDoExportBoolean then begin
LocalLineNoInteger += 10000;
LocalRecordSIMEDSQueueLine.Init();
LocalRecordSIMEDSQueueLine."Queue Entry No." := GlobalCodeunitSIMEDSSI.GetCodeunitQueueID();
LocalRecordSIMEDSQueueLine."Line No." := LocalLineNoInteger;
LocalRecordSIMEDSQueueLine.Type := ParamRecordSIMEDSRecordAttachment.Type;
LocalRecordSIMEDSQueueLine."Attachment Group" := ParamRecordSIMEDSRecordAttachment."Attachment Group";
LocalRecordSIMEDSQueueLine."Record Attachment Line No." := ParamRecordSIMEDSRecordAttachment."Line No.";
LocalRecordSIMEDSQueueLine.Description := ParamRecordSIMEDSRecordAttachment.Description;
LocalRecordSIMEDSQueueLine."Source ID" := LocalResultRecordRef.RecordId;
LocalRecordSIMEDSQueueLine."Codeunit File Found" := true;
LocalRecordSIMEDSQueueLine."Optional Attachment" := ParamRecordSIMEDSRecordAttachment."Optional Attachment";
LocalRecordSIMEDSQueueLine."Attach Tag" := ParamRecordSIMEDSRecordAttachment."Default selection";
case ParamRecordSIMEDSRecordAttachment."Codeunit PDF Type" of
//PDF
ParamRecordSIMEDSRecordAttachment."Codeunit PDF Type"::PDF,
ParamRecordSIMEDSRecordAttachment."Codeunit PDF Type"::"PDF/A-3":
begin
LocalFilenameTempText := 'Test.pdf';
// Convert file to Base64 and write to queue line
LocalFileBase64StringText := 'BASE64STRING';
end;
// Word
ParamRecordSIMEDSRecordAttachment."Codeunit PDF Type"::"Word":
begin
LocalFilenameTempText := 'Test.docx';
LocalFileBase64StringText := 'BASE64STRING';
end;
//Excel
ParamRecordSIMEDSRecordAttachment."Codeunit PDF Type"::"Excel":
begin
LocalFilenameTempText := 'Test.xlsx';
LocalFileBase64StringText := 'BASE64STRING';
end;
//XML
ParamRecordSIMEDSRecordAttachment."Codeunit PDF Type"::"XML":
begin
LocalFilenameTempText := 'Test.xml';
LocalFileBase64StringText := 'BASE64STRING';
end;
end;
LocalRecordSIMEDSQueueLine."Document Name" := CopyStr(LocalFilenameTempText, 1, 250);
LocalRecordSIMEDSQueueLine."Filename Extension" := CopyStr(
LocalCodeunitSIMCOREText.GetFileExtension(LocalRecordSIMEDSQueueLine."Document Name"),
1,
MaxStrLen(LocalRecordSIMEDSQueueLine."Filename Extension")
);
Clear(LocalOOutStream);
LocalRecordSIMEDSQueueLine."Document Blob".CreateOutStream(LocalOOutStream);
LocalCodeunitBase64Convert.FromBase64(LocalFileBase64StringText, LocalOOutStream);
// Insert the queue line
LocalRecordSIMEDSQueueLine.Insert();
end;
until LocalResultRecordRef.Next() = 0;
GlobalCodeunitSIMEDSSI.SetCodeunitQueueLineNo(LocalLineNoInteger);
end;
}
|