Skip to content

Uploading Documents via code over DMS (Old)

In this documentation we will create an extension that allows uploading documents from a BLOB to DMS via Code. When it comes to the upload without user interaction, please use the Document Inbound app. Extending a report with DMS code is used so that when a report is printed or a document is posted/converted, it is possible to automatically generate and add a DMS Barcode during that process.

The following requirements must be met:

  • The DMS module must be licensed.
  • CORE by Simova must be available in the extension as a reference.
  • DMS by Simova must be present in the extension as a reference.

Upload a File with User Interaction:

The UploadFileDialog function opens user interactions such as replacing/renaming and selecting the content type before the document is uploaded to the repository.

Overload 1:

Var Name Data Type Sub Type Length Description
No Filename Text The original file name of the document
No Base64File Text The file as a base64 string
No RRef RecordRef The data record reference to which the document must be uploaded

The function outputs:

Name Data Type Length Description
Boolean The original file name of the document

Code Example:

AL
var
    SalesHeader: Record "Sales Header";
    UploadMgt: Codeunit "SIM_DMS Upload Mgt";
    FileManagement: Codeunit "File Management";
    Base64Convert: Codeunit "Base64 Convert";
    TempBlob: Codeunit "Temp Blob";
    RRef: RecordRef;
    InStr: InStream;
    Filename: Text;
    Base64File: Text;
    AllFilesFilterTxt: Label '*.*', Locked = true;
    AllFilesDescriptionTxt: Label 'All Files (*.*)|*.*', Comment = '{Split=r''\|''}{Locked=s''1''}';
    DialogCaptionTxt: Label 'Choose Upload File';
begin
    Filename := FileManagement.BLOBImportWithFilter(TempBlob, DialogCaptionTxt, '', AllFilesDescriptionTxt, AllFilesFilterTxt);
    Filename := FileManagement.GetFileName(Filename);
    if Filename = '' then exit;

    Clear(InStr);
    TempBlob.CreateInStream(InStr);
    Base64File := Base64Convert.ToBase64(InStr);

    SalesHeader.Reset();
    SalesHeader.Findfirst();
    RRef.GetTable(SalesHeader);

    UploadMgt.UploadFileDialog(Filename, Base64File, RRef);
end

Upload a File silently:

The UploadFileSilent function uploads a document with the specified parameters to DMS without any user interaction. There are various overloads to specify the document.

Overload 1:

Var Name Data Type Sub Type Length Description
No Title Text The title or name that the repository should use.
No Filename Text The original file name of the document.
No Base64File Text The file as a base64 string.
No RRef RecordRef The data record reference to which the document must be uploaded.

Overload 2:

Var Name Data Type Sub Type Length Description
No Title Text The title or name that the repository should use.
No Filename Text The original file name of the document.
No Base64File Text The file as a base64 string.
No RRef RecordRef The data record reference to which the document must be uploaded.
No ContentType Text The content type with which the document is uploaded.

Overload 3:

Var Name Data Type Sub Type Length Description
No Title Text The title or name that the repository should use.
No Filename Text The original file name of the document.
No Base64File Text The file as a base64 string.
No RRef RecordRef The data record reference to which the document must be uploaded.
No MetadataTmp Record "SIM_DMS Document Metadata" A temporary record with metadata whiich exists in the Content Type or Standard Content Type.

Overload 4:

Var Name Data Type Sub Type Length Description
No Title Text The title or name that the repository should use.
No Filename Text The original file name of the document.
No Base64File Text The file as a base64 string.
No RRef RecordRef The data record reference to which the document must be uploaded.
No ContentType Text The content type with which the document is uploaded.
No MetadataTmp Record "SIM_DMS Document Metadata" A temporary record with metadata whiich exists in the Content Type or Standard Content Type.

The function outputs:

Name Data Type Length Description
Boolean Returns true if the action was successful.

Code Example:

AL
var
    SalesHeader: Record "Sales Header";
    UploadMgt: Codeunit "SIM_DMS Upload Mgt";
    FileManagement: Codeunit "File Management";
    Base64Convert: Codeunit "Base64 Convert";
    TempBlob: Codeunit "Temp Blob";
    RRef: RecordRef;
    InStr: InStream;
    Filename: Text;
    Base64File: Text;
    AllFilesFilterTxt: Label '*.*', Locked = true;
    AllFilesDescriptionTxt: Label 'All Files (*.*)|*.*', Comment = '{Split=r''\|''}{Locked=s''1''}';
    DialogCaptionTxt: Label 'Choose Upload File';
begin
    Filename := FileManagement.BLOBImportWithFilter(TempBlob, DialogCaptionTxt, '', AllFilesDescriptionTxt, AllFilesFilterTxt);
    Filename := FileManagement.GetFileName(Filename);
    if Filename = '' then exit;

    Clear(InStr);
    TempBlob.CreateInStream(InStr);
    Base64File := Base64Convert.ToBase64(InStr);

    SalesHeader.Reset();
    SalesHeader.Findfirst();
    RRef.GetTable(SalesHeader);

    UploadMgt.UploadFileSilent(Filename,Filename, Base64File, RRef);
end

Upload multiple files silently:

The UploadMultiFileSilent function uploads several documents with the specified parameters to DMS without user interaction. There are various overloads to specify the documents.

Overload 1:

Var Name Data Type Sub Type Length Description
No ParamTitleListOfText List of texts 250 The title or name that the repository should use.
No ParamFilenameListOfText List of texts 250 The original file name of the document.
No ParamBase64FileListOfText List of texts The file as a base64 string.
No ParamRecordRef RecordRef The data record reference to which the document must be uploaded.
No ParamContentTypeListOfText List of texts 100 The content type with which the document is uploaded.
Yes ParamRecordTempSIMDMSDocumentMetadata RecordRef "SIM_DMS Document Metadata" A temporary data record with metadata that exists in the content type or standard content type.
No ParamBooleanOneGroupID RecordRef Specifies whether the files should be added to a single new group or whether each file should be added to a new group.

Overload 2:

Var Name Data Type Sub Type Length Description
No ParamTitleListOfText List of texts 250 The title or name that the repository should use.
No ParamFilenameListOfText List of texts 250 The original file name of the document.
No ParamBase64FileListOfText List of texts The file as a base64 string.
No ParamRecordRef RecordRef The data record reference to which the document must be uploaded.
Yes ParamRecordTempSIMDMSDocumentMetadata RecordRef "SIM_DMS Document Metadata" A temporary data record with metadata that exists in the content type or standard content type.
Yes ParamBooleanOneGroupID RecordRef Specifies whether the files should be added to a single new group or whether each file should be added to a new group.

Code Example:

AL
var
    TempSIMDMSDocumentMetadata: Record "SIM_DMS Document Metadata" temporary;
    UploadMgt: Codeunit "SIM_DMS Upload Mgt";
    FileManagement: Codeunit "File Management";
    Base64Convert: Codeunit "Base64 Convert";
    SIMCOREText: Codeunit "SIM_CORE Text";
    TempBlob: Codeunit "Temp Blob";
    SIMDMSMgt: Codeunit "SIM_DMS Mgt.";
    RRef: RecordRef;
    InStr: InStream;
    Filename: Text;
    Base64File: Text;
    AllFilesFilterTxt: Label '*.*', Locked = true;
    AllFilesDescriptionTxt: Label 'All Files (*.*)|*.*', Comment = '{Split=r''\|''}{Locked=s''1''}';
    DialogCaptionTxt: Label 'Choose Upload File';
    ListTitle: List of [Text[250]];
    ListFilename: List of [Text[250]];
    ListBase64: List of [Text];
    ListContentType: List of [Text[100]];
begin
    RRef.GetTable(Rec);

    Filename := FileManagement.BLOBImportWithFilter(TempBlob, DialogCaptionTxt, '', AllFilesDescriptionTxt, AllFilesFilterTxt);
    Clear(InStr);
    TempBlob.CreateInStream(InStr);
    ListBase64.Add(Base64Convert.ToBase64(InStr));
    ListTitle.Add(SIMCOREText.GetFilenameWithoutExtension(FileManagement.GetFileName(Filename)));
    ListFilename.Add(FileManagement.GetFileName(Filename));

    Filename := FileManagement.BLOBImportWithFilter(TempBlob, DialogCaptionTxt, '', AllFilesDescriptionTxt, AllFilesFilterTxt);
    Clear(InStr);
    TempBlob.CreateInStream(InStr);
    ListBase64.Add(Base64Convert.ToBase64(InStr));
    ListTitle.Add(SIMCOREText.GetFilenameWithoutExtension(FileManagement.GetFileName(Filename)));
    ListFilename.Add(FileManagement.GetFileName(Filename));

    Filename := FileManagement.BLOBImportWithFilter(TempBlob, DialogCaptionTxt, '', AllFilesDescriptionTxt, AllFilesFilterTxt);
    Clear(InStr);
    TempBlob.CreateInStream(InStr);
    ListBase64.Add(Base64Convert.ToBase64(InStr));
    ListTitle.Add(SIMCOREText.GetFilenameWithoutExtension(FileManagement.GetFileName(Filename)));
    ListFilename.Add(FileManagement.GetFileName(Filename));

    ListContentType.Add('Other Documents');
    ListContentType.Add('Other Documents');
    ListContentType.Add('E-Mail');

    SIMDMSMgt.CreateMappingMetaData(TempSIMDMSDocumentMetadata, RRef);

    UploadMgt.UploadMultiFileSilent(ListTitle, ListFilename, ListBase64, RRef, ListContentType, TempSIMDMSDocumentMetadata, true);
end

Utilize Archive Queue for Document Upload (OLD)

The ArchiveDocument function loads the specified file with the corresponding parameters and metadata into the archive queue. The job queue processes the document and uploads it to the repository with a delay.

We do not recommend using this action. The archive queue is reserved for reports. Please use the Document Inbound App for this process instead.

Overload 1:

Var Name Data Type Sub Type Length Description
No Title Text The title or name that the repository should use.
No Filename Text The original file name of the document.
No RRef RecordRef The data record reference to which the document must be uploaded.

Overload 2:

Var Name Data Type Sub Type Length Description
No Title Text The title or name that the repository should use.
No Filename Text The original file name of the document.
No RRef RecordRef The data record reference to which the document must be uploaded.
No ContentType Text The content type with which the document is uploaded.

Overload 3:

Var Name Data Type Sub Type Length Description
No Title Text The title or name that the repository should use.
No Filename Text The original file name of the document.
No RRef RecordRef The data record reference to which the document must be uploaded.
No MetadataTmp Record "SIM_DMS Document Metadata" A temporary record with metadata whiich exists in the Content Type or Standard Content Type.

Overload 4:

Var Name Data Type Sub Type Length Description
No Title Text The title or name that the repository should use.
No Filename Text The original file name of the document.
No RRef RecordRef The data record reference to which the document must be uploaded.
No ContentType Text The content type with which the document is uploaded.
No MetadataTmp Record "SIM_DMS Document Metadata" A temporary record with metadata whiich exists in the Content Type or Standard Content Type.

The function outputs:

Name Data Type Length Description
BigInteger Returns the entry number of the data record SIM_DMS archive queue entry.

Code Example:

AL
var
    SalesHeader: Record "Sales Header";
    UploadMgt: Codeunit "SIM_DMS Upload Mgt";
    FileManagement: Codeunit "File Management";
    Base64Convert: Codeunit "Base64 Convert";
    TempBlob: Codeunit "Temp Blob";
    RRef: RecordRef;
    InStr: InStream;
    Filename: Text;
    Base64File: Text;
    AllFilesFilterTxt: Label '*.*', Locked = true;
    AllFilesDescriptionTxt: Label 'All Files (*.*)|*.*', Comment = '{Split=r''\|''}{Locked=s''1''}';
    DialogCaptionTxt: Label 'Choose Upload File';
begin
    Filename := FileManagement.BLOBImportWithFilter(TempBlob, DialogCaptionTxt, '', AllFilesDescriptionTxt, AllFilesFilterTxt);
    Filename := FileManagement.GetFileName(Filename);
    if Filename = '' then exit;

    Clear(InStr);
    TempBlob.CreateInStream(InStr);
    Base64File := Base64Convert.ToBase64(InStr);

    SalesHeader.Reset();
    SalesHeader.Findfirst();
    RRef.GetTable(SalesHeader);

    UploadMgt.ArchiveDocument(Base64File, Filename, RRef);
end

Get Metadata for RecordRef

The GetMetadata function returns all metadata for the specified RecordRef according to the settings.

Overload 1:

Var Name Data Type Sub Type Length Description
Yes MetadataTmp Record "SIM_DMS Document Metadata" The GetMetadata function returns all metadata for the specified RecordRef according to the settings.
No RRef RecordRef The data record reference to which the document must be uploaded.

Archive Report by Printing

The ArchiveReportByPrinting function prints the corresponding report for this table and the primary key of the RRef. In this case, the data record is not filtered to the current data record.

In the report settings, you can see what is set for the report. Here you can also specify whether the report is executed via the job queue.

Var Name Data Type Sub Type Length Description
No RRef RecordRef The data record reference to which the document must be uploaded.

The function outputs:

Name Data Type Sub Type Length Description
RRef BigInteger Returns the entry number of the data record SIM_DMS archive queue entry.

Code Example:

AL
var
    SalesHeader: Record "Sales Header";
    UploadMgt: Codeunit "SIM_DMS Upload Mgt";
    RRef: RecordRef;
begin
    SalesHeader.Reset();
    SalesHeader.Findfirst();
    RRef.GetTable(SalesHeader);

    UploadMgt.ArchiveReportByPrinting(RRef);
end

Archive Report by Posting

The ArchiveReportByPosting function prints the corresponding report for this table and the primary key of the RRef. In this case, the data record is filtered out of the current data record.

In the report settings, you can see what is set for the report. Here you can also specify whether the report is executed via the job queue.

Var Name Data Type Sub Type Length Description
No RRef RecordRef The data record reference to which the document must be uploaded.

The function outputs:

Name Data Type Sub Type Length Description
RRef BigInteger Returns the entry number of the data record SIM_DMS archive queue entry.

Code-Example:

AL
var
    SalesHeader: Record "Sales Header";
    UploadMgt: Codeunit "SIM_DMS Upload Mgt";
    RRef: RecordRef;
begin
    SalesHeader.Reset();
    SalesHeader.Findfirst();
    RRef.GetTable(SalesHeader);

    UploadMgt.ArchiveReportByPosting(RRef);
end

Archive Report by Report ID

The ArchiveReportByReportId function prints the specified report. The report and the data record must match.

In the report settings, you can see what is set for the report. Here you can also specify whether the report is executed via the job queue.

Var Name Data Type Sub Type Length Description
No RRef RecordRef The data record reference to which the document must be uploaded.
No ReportNo Integer The number of the report to be archived.

The function outputs:

Name Data Type Sub Type Length Description
RRef BigInteger Returns the entry number of the data record SIM_DMS archive

Code-Example:

AL
var
    SalesHeader: Record "Sales Header";
    UploadMgt: Codeunit "SIM_DMS Upload Mgt";
    RRef: RecordRef;
begin
    SalesHeader.Reset();
    SalesHeader.Findfirst();
    RRef.GetTable(SalesHeader);

    UploadMgt.ArchiveReportByReportId(RRef,1304);
end