Skip to content

Download documents by code from Document Central

Document Central can be extended with code to enable downloading documents from a Document Central entry. The following documentation explains how to create an extension that allows you to download documents from a Document Central entry via code.

The following requirements must be met:

  • Document Central must be present in the extension for reference.

Download file:

The DownloadFile function downloads a document by code.

Overload 1:

Var Name Data Type Subtype Length Description
No ParamRecordSIMDMSDocumentEntry Record "SIM_DMS Document Entry" The Document Central document entry that is downloaded
No ParamDownloadInAppContext Boolean Defines whether the download is performed in the App Context or in the User Context

The function outputs:

Name Data Type Length Description
ReturnBase64FileText Text The downloaded document as Base64

Code Example:

In this example, a document that has been stored on the customer 01121212 and the file name 103035.pdf is downloaded with an App context.

AL
var
    LocalRecordSIMDMSDocumentEntry: Record "SIM_DMS Document Entry";
    LocalRecordSMIDMSModuleSetup: Record "SIM_DMS Module setup";
    LocalCodeunitSIMDMSDownloadMgt: Codeunit "SIM_DMS Download Mgt";
    LocalCodeunitFileManagement: Codeunit "File Management";
    LocalCodeunitTempBlob: Codeunit "Temp Blob";
    LocalCodeunitBase64Convert: Codeunit "Base64 Convert";
    LocalOutStream: OutStream;
begin
    LocalRecordSMIDMSModuleSetup.Get();
    LocalRecordSIMDMSDocumentEntry.Get(LocalRecordSMIDMSModuleSetup."Repository Code", '/2024/', 'DEBITOR', 01121212, '103035.pdf');

    LocalCodeunitTempBlob.CreateOutStream(LocalOutStream);
    LocalCodeunitBase64Convert.FromBase64(LocalCodeunitSIMDMSDownloadMgt.DownloadFile(LocalRecordSIMDMSDocumentEntry, true), LocalOutStream);

    LocalCodeunitFileManagement.BLOBExport(LocalCodeunitTempBlob, LocalRecordSIMDMSDocumentEntry.Filename, true);
end;

Download file version:

The DownloadFileVersion function downloads a document by code.

Overload 1:

Var Name Data Type Subtype Length Description
No ParamRecordSIMDMSDocumentEntryVersion Record "SIM_DMS Document Entry Version" The Document Central document Version entry that is downloaded

Overload 2:

Var Name Data Type Subtype Length Description
No ParamRecordSIMDMSDocumentEntryVersion Record "SIM_DMS Document Entry Version" The Document Central document Version entry that is downloaded
No ParamDownloadInAppContext Boolean Defines whether the download is performed in the App Context or in the User Context

The function outputs:

Name Data Type Length Description
ReturnBase64FileText Text The downloaded document as Base64

Code Example:

In this example, the second version of the document that has been stored on the customer 01121212 and the file name 103035.pdf is downloaded with an App context.

AL
var
    LocalRecordSIMDMSDocumentEntryVersion: Record "SIM_DMS Document Entry Version";
    LocalRecordSMIDMSModuleSetup: Record "SIM_DMS Module setup";
    LocalCodeunitSIMDMSDownloadMgt: Codeunit "SIM_DMS Download Mgt";
    LocalCodeunitFileManagement: Codeunit "File Management";
    LocalCodeunitTempBlob: Codeunit "Temp Blob";
    LocalCodeunitBase64Convert: Codeunit "Base64 Convert";
    LocalOutStream: OutStream;
begin
    LocalRecordSMIDMSModuleSetup.Get();
    if not LocalRecordSIMDMSDocumentEntryVersion.Get(LocalRecordSMIDMSModuleSetup."Repository Code", '/2024/', 'DEBITOR', 01121212, '103035.pdf',2) then
        exit;

    LocalCodeunitTempBlob.CreateOutStream(LocalOutStream);
    LocalCodeunitBase64Convert.FromBase64(LocalCodeunitSIMDMSDownloadMgt.DownloadFileVersion(LocalRecordSIMDMSDocumentEntryVersion, true), LocalOutStream);

    LocalCodeunitFileManagement.BLOBExport(LocalCodeunitTempBlob, LocalRecordSIMDMSDocumentEntryVersion.Filename, true);
end;