Uso de una Codeunit definida por el usuario para un anexo de envío
En esta documentación, crearemos una unidad de código de muestra que permite la integración de código externo, lo que permite a Document Dispatch enviar archivos recibidos a través de una unidad de código.
Se deben cumplir los siguientes requisitos:
La extensión de envío de documentos debe tener licencia.
Se debe hacer referencia a la extensión Document Dispatch en la extensión personalizada.
Unidad de código personalizado de despacho de documentos:
| 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
// Check if the codeunit is set up
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();
// Retrieve the record reference from the 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;
// Iterate through the result records
if LocalResultRecordRef.FindSet() then
repeat
LocalDoExportBoolean := false;
// Logic to determine if the record should be exported
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;
}
|