| Docs Help
  AppSource  
Docs  /  NAVAX Extension Base  /  Information for Developers

 Dropzone


2024/08/06 • 4 min. to read
A NAVAX Dropzone can be integrated into a page very easily. Each added dropzone is addressed and identified by a unique ID.

Note

NAVAX Dropzones are suitable for upload sizes up to 15000 KB (15 MB).
The following example shows how to add a new dropzone.

Scenario

  • A dropzone should be provided on the customer list (Page 22), which can be used to add document attachments via drag & drop:

    Note

    This example serves only to illustrate the simplest implementation. For document attachments, it is recommended to use the NAVAX App NAVAX Drag & Drop Document Attachments. This app is also based on NAVAX Dropzone, but integrates it directly with the document attachment FactBox. For more information, see [Docs] NAVAX Drag & Drop Document Attachments - General

Implementation

  1. enumextension A NAVAX Dropzone triggers the OnAfterUpload event on a successful "Drag & Drop". The NCEXDropzoneID parameter of the event specifies which Dropzone triggered the event. For each new Dropzone an additional NCEXDropzoneID must be defined, so that it can be uniquely identified in the event. A new NCEXDropzoneID is added or created via an enumextension:
    enumextension 50000 "NVXTEST NCEX Dropzone ID" extends "NCEX Dropzone ID"
    {
        value(50000; "NVXTEST Customer")
        {
            Caption = 'NVXTEST Customer', Comment = 'DEU="NVXTEST Debitor"';
        }
    }
    Through this enum extension, the customer will also have the ability to specify the settings and defaults for the new Dropzone later on the NAVAX Dropzone Setup page:
  2. Add Dropzone The new Dropzone can then be added to the customer list, e.g. as a FactBox:
    pageextension 50000 "NVXTEST Customer List" extends "Customer List"
    {
        layout
        {
            addfirst(factboxes)
            {
                part(NVXTESTDropzone; "NCEX Dropzone")
                {
                    ApplicationArea = All;
                    Visible = true;
                }
            }
        }
    
        trigger OnOpenPage()
        begin
            CurrPage.NVXTESTDropzone.Page.SetDropzoneID("NCEX Dropzone ID"::"NVXTEST Customer");
        end;
    
        trigger OnAfterGetCurrRecord()
        begin
            CurrPage.NVXTESTDropzone.Page.SetCurrRecord(Rec);
        end;
    }

    Note

    This block:
    trigger OnAfterGetCurrRecord()
    begin
        CurrPage.NVXTESTDropzone.Page.SetCurrRecord(Rec);
    end;
    can also be omitted if, for example, you need a Dropzone that is not record related. (e.g. import of payment files of the NAVAX App NCPI Payments Import).

    Note

    An overload with the following additional parameters is also available for the SetDropzoneID function:
    • AdditionalCallID Can be used as needed, and is passed to the OnAfterUpload Event. For example, if several pages share the same NCEXDropzoneID, you can specify the ID of the page (e.g. Page:: "Purchase Invoices") as a parameter and query it later in the event.
    • AdditionalDropzoneText Can be used if necessary to display additional information to users in the Dropzone area.

  3. OnAfterUpload Event The last step is now to react to the OnAfterUpload event of the Dropzone:
    codeunit 50000 "NVXTEST Event Mgt."
    {
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"NCEX Dropzone Mgt.", 'OnAfterUpload', '', false, false)]
        local procedure NVXTEST_NCEXDropzoneMgt_OnAfterUpload(NCEXDropzoneID: Enum "NCEX Dropzone ID"; CurrRecordVariant: Variant; var UploadedTempBlobList: Codeunit "Temp Blob List"; FileNameList: List of [Text]; AdditionalCallID: Integer)
        var
            Customer: Record Customer;
            DocumentAttachment: Record "Document Attachment";
            TempBlob: Codeunit "Temp Blob";
            ConfirmManagement: Codeunit "Confirm Management";
            RecordRef: RecordRef;
            InStream: InStream;
            FileName: Text;
            i: Integer;
            NoOfFiles: Integer;
            NoOfNoContentFiles: Integer;
            NoRecordSelectedErr: Label 'No %1 is selected.', Comment = 'DEU="Es ist kein %1 ausgewählt."';
            UploadMsg: Label 'Do you want to add %1 file(s) to the document attachments of %2 ''%3''?.', Comment = 'DEU="Möchten Sie %1 Datei(en) zu den Beleganhängen von %2 ''%3'' hinzufügen?"';
            NoContentFilesMsg: Label 'Files that have no content cannot be added to the document attachments.\\Number of files not added: %1\Number of files added: %2', Comment = 'DEU="Dateien, die keinen Inhalt haben, können nicht zu den Beleganhängen hinzugefügt werden.\\Anzahl nicht hinzugefügter Dateien: %1\Anzahl hinzugefügter Dateien: %2"';
        begin
            if (NCEXDropzoneID <> NCEXDropzoneID::"NVXTEST Customer") then
                exit;
    
            if (UploadedTempBlobList.Count() = 0) then
                exit;
    
            if not CurrRecordVariant.IsRecord() then
                Error(NoRecordSelectedErr, Customer.TableCaption());
            Customer := CurrRecordVariant;
            if (Customer."No." = '') then
                Error(NoRecordSelectedErr, Customer.TableCaption());
            Customer.Get(Customer."No.");
    
            if not ConfirmManagement.GetResponseOrDefault(StrSubstNo(UploadMsg, UploadedTempBlobList.Count(), Customer.TableCaption(), Customer."No."), true) then
                exit;
    
            RecordRef.GetTable(Customer);
            NoOfFiles := 0;
            NoOfNoContentFiles := 0;
            for i := 1 to UploadedTempBlobList.Count() do begin
                UploadedTempBlobList.Get(i, TempBlob);
                if TempBlob.HasValue() then begin
                    FileNameList.Get(i, FileName);
                    TempBlob.CreateInStream(InStream);
                    Clear(DocumentAttachment);
                    DocumentAttachment.Init();
                    DocumentAttachment.InitFieldsFromRecRef(RecordRef);
                    DocumentAttachment.SaveAttachmentFromStream(InStream, RecordRef, FileName);
                    NoOfFiles += 1;                
                end else
                    NoOfNoContentFiles += 1;
            end;
    
            if (NoOfNoContentFiles <> 0) then
                Message(NoContentFilesMsg, NoOfNoContentFiles, NoOfFiles);
        end;
    }

    Important

    if (NCEXDropzoneID <> NCEXDropzoneID::"NVXTEST Customer") then
        exit;
    This if-condition decides for which Dropzone the code should be executed and must not be omitted under any circumstances. The value must match the added value from the enumextension.


Submit feedback for
DE|EN Imprint