Technical Notes, Zetadocs

HOWTO: How to automatically archive linked items using Zetadocs Capture

ZTN3616

This Zetadocs technical note applies to:

  • Version 8.0 of Zetadocs for NAV or later
  • Microsoft Dynamics NAV 2015 or later

Summary

This article demonstrates how to automatically archive linked items from a Zetadocs Document Queue programmatically. The example provided in the following steps describes how to create a NAV Codeunit that contains a function that calls the Zetadocs Capture Interface Codeunit. Please note that you can extend or modify the example to suit your needs or requirements.

More information

The steps described in the following section assume that Zetadocs is correctly setup and configured to use Zetadocs Capture Plus. They have been written for a Microsoft Dynamics NAV 2015 system configured to use Zetadocs Capture. Similar steps may apply to later versions of Dynamics NAV.

Due to missing functionality within Microsoft Dynamics NAV 2013, this will not work with any NAV environment version 2013 or earlier. This will require NAV 2015 at minimum.

Prerequisite: Enter the archiving credentials in SharePoint

Zetadocs needs stored credentials to archive files to your SharePoint site.

If you are using the Zetadocs Any Client Factbox in the Web Client:

  1. Create a test file.
  2. Open the Microsoft Dynamics NAV Web Client as the user that will run the automation.
  3. Open the Zetadocs Any Client Factbox in any page modified page, e.g. Sales Invoice page.
  4. If your credentials are not in the server, Zetadocs will display a dialog. Insert your credentials.
  5. Delete the test file from your Archiving site; to do so, delete the test file in the Factbox.

If you are using the Zetadocs Windows Client Factbox:

  1. Drop a test file to any Document Queue in the Zetadocs Server (Zetadocs Document Converter).
  2. Open the Microsoft Dynamics NAV Web Client as the user that will run the automation.
  3. Open the Zetadocs Document Queue page, select the Queue which contains the document and click Ok.
  4. Select the test document and click the Archive button.
  5. If your credentials are not in the server, Zetadocs will display a dialog. Insert your credentials.
  6. Close the Zetadocs Document Queue page.
  7. Delete the test file from your Archiving site and from the Document Queue if it has not already been deleted.

Step 1: Create a Codeunit

  1. Open the Microsoft Development Environment and open the Object Designer. Select the Codeunit tab.
  2. Create a new Codeunit: File -> New.
  3. Save and Compile the new Codeunit, type a name and an ID, e.g. Codeunit Name: Automate Document Queue, ID: 51001.

Step 2: Call Zetadocs Capture Interface

  1. Open the Microsoft Development Environment and open the Object Designer. Select the Codeunit tab.
  2. Select the Codeunit created in the previous step and click on Design.
  3. Create a new public function:
    1. View->C/AL Globals, select the Functions tab.
    2. Insert the name of the function, e.g. ArchiveAllLinkedRecords.
    3.  Go to the properties of the function (View->Properties) and change “Local: No”.
    4. Close the Properties dialog.
    5. In the Functions tab of the C/AL Globals dialog select the function you have added (e.g. ArchiveAllLinkedRecords) and click on Locals.
    6. Add a new Parameter:

  1. Create new Local Variables:
    1. Select the Variables tab.
    2. Add the following variables:

                                          i.    Name: ZdDocQueueItem

DataType: Record

Subtype: Zetadocs Doc. Queue Item

                                         ii.    Name: ZdDocQueueItemTmp

DataType: Record

Subtype: Zetadocs Doc. Queue Item

Note: this is a temporary variable. Select it and open the properties dialog (View->Properties), then change “Temporary: Yes”:

                                        iii.    Name: ZdCaptureInterface

DataType: Codeunit

Subtype: Zetadocs-Capture Interface

  1. Close the dialogs and go back to the one that contains the code.
  2. Scroll to the body of the function created previously and paste the following code:

//Initialize the Zetadocs Capture Interface codeunit with the Zetadocs Document Queue (passed as a parameter)

ZdCaptureInterface.Initialize(ZetadocsDocQueueNo);

//Fetch the documents from the Document Queue on the Zetadocs Server

ZdCaptureInterface.Refresh();

//Once the documents are fetched, they exist in the Zetadocs Document Queue table.

//Get all the items related to the Zetadocs Document Queue

ZdDocQueueItem.RESET;

ZdDocQueueItem.SETRANGE("Zetadocs Doc. Queue No.", ZetadocsDocQueueNo);

IF ZdDocQueueItem.FIND('-') THEN

BEGIN

  REPEAT

    //Create a temp item for each document in the Zetadocs Document Queue

    ZdDocQueueItemTmp.DELETEALL(FALSE);

    ZdDocQueueItemTmp := ZdDocQueueItem;

    ZdDocQueueItemTmp.INSERT;

    //Archive the document if it has a link

    IF (NOT ZdCaptureInterface.ArchiveLinkedRecord(ZdDocQueueItemTmp)) THEN

    BEGIN     

      //There is an error archiving the item

      //Check if the entire batch should fail

      IF (ZdCaptureInterface.GetStopBatchProcessing()) THEN

      BEGIN

        //Display corresponding error

        //Comment the following line if you do not want to stop the processing of the batch

        ERROR('Stop batch processing is enabled. Queue: %1. Document %2 failed: %3', ZetadocsDocQueueNo, ZdDocQueueItemTmp."File Name", ZdCaptureInterface.GetLastErrorMessage());

      END;

    END;

  UNTIL ZdDocQueueItem.NEXT = 0;

END;

//Release the Capture Interface

ZdCaptureInterface.Clear();

  1. Close the dialogs, save and compile the Codeunit.

Step 3: Test your system

In order to test this example you just need to call the function as follows:

ArchiveAllLinkedRecords(<ZetadocsDocumentQueueNo>);

Where <ZetadocsDocumentQueueNo> is the Zetadocs Document Queue Number, e.g. ZDQ0002.

Please ensure that everything works as expected before deploying it live.

Tip: An easy way to test your system is to add the previous call to the OnRun trigger of the Codeunit that has been created in the previous step. Save and compile the Codeunit. And, run it from the Development Environment.

There are alternative ways to test this example depending on your needs or requirements, for example you can call this Codeunit from the NAV Job Queue or you may expose the Codeunit as a NAV Web Service.

Note: if you are using NAV Job Queues you may need to repeat the Prerequisite (at the beginning of this article) and you may need to login as the user that is running the NAV Job Queue. Please remember that NAV Job Queues run the OnRun trigger, so you may need to add a call to ArchiveAllLinkedRecords in this trigger.

Note2: If you are using the NAV Job Queues you need to set the interval between runs to at least 60min. This will allow NAV to dispose the memory that it allocated for Zetadocs for NAV to run.Last updated:

2nd October 2017 (JV/GC/NT/JC) 

Keywords: Zetadocs Capture Autolink Codeunit 9009986 Zetadocs-Capture Integration