Equisys technical notes

Technical guidance, explanations and fixes for our products

HOWTO: Use NAS to implement auto linking

Print

ZTN4121

ID: ZTN4121

This Zetadocs technical note applies to:

  • Zetadocs for NAV v4.1 onwards.
  • Microsoft Dynamics NAV versions 4, 5 and 6

Summary

Using NAS and the NAV Job Queue, Zetadocs for NAV can be set up to automate the linking of documents from a custom Document Queue. This technote provides some sample code of how to write a CodeUnit which can be run from a NAS service, please note that these steps are not compatible with NAV 2013 as it uses a different type of NAS as part of the service tier - NST. The example code writes a log file for troubleshooting errors, however, it is recommended that you implement your own error handling method.

Prerequisites

  1. You have a configured your Navision Application Server to run jobs from the job queue. (i.e. Ensure the NAS service is started and the Start-Up Parameter is set to JOBQUEUE)
  2. You have installed the Zetadocs for NAV Client components on the machine where your NAS service runs. You must choose to install the licensing and configurations components (Administrator or Custom install).

More information

Follow these steps to schedule auto linking:

  1. Copy the content from the Zetadocs-Autolink section below, into a text file called Zetadocs-Autolink.txt.
  2. Import this Zetadocs-Autolink.txt file into the Object Designer of NAV ensuring that it will not overwrite any other CodeUnits. It will have an ID of 50000 unless you wish to edit it by altering the number at the top of the code.
  3. Use the job queue to schedule this CodeUnit to run at a convenient time. Preferably when the queue is not in use.
  4. By default the CodeUnit will run auto link on the first Document Queue. You can change this by editing the CodeUnit. Ensure whichever queue you intend running auto link on has the Auto Link Documents checkbox ticked via the Zetadocs Document Queue Setup.
  5. A log file will be written to C:\Zetadocs-Autolink. Change this if you would prefer it to be written somewhere else.

For more information see section 15.6 of the Zetadocs for Nav Installation Guide – “Additional code required for document linking and archiving (Custom Queues Only)” and follow the Sales Shipment example.

 

Zetadocs-Autolink CodeUnit

OBJECT Codeunit 50000 Zetadocs-Autolink PageInterval

{

  OBJECT-PROPERTIES

  {

    Date=01/04/11;

    Time=14:56:13;

    Modified=Yes;

    Version List=;

  }

  PROPERTIES

  {

    OnRun=VAR

            LogFileName@1000000000 : Text[250];

          BEGIN

            // Get the queue settings.

            IF NOT QueueSettings.FIND('-') THEN

            BEGIN

              EXIT;

            END;

            // Set up the log file.

            LogFileName := 'C:\Zetadocs-Autolink '+QueueSettings." No." +'.txt';

            IF EXISTS(LogFileName) THEN

            BEGIN

                ERASE(LogFileName);

            END;

            WriteToLog(LogFileName, 'Zetadocs-Autolink started.');

            // Initialize the queue by specifying the queue number.

            IF NOT ZdCapture.Initialize(QueueSettings." No." ) THEN

            BEGIN

              WriteToLog(LogFileName, ' Could not initialize the queue. '+ ZdCapture.GetLastErrorMessage);

              EXIT;

            END;

            // Check that the autolink flag is set. This can be done via the Document Queue Settings form.

            IF NOT QueueSettings." Auto Link" THEN

            BEGIN

              WriteToLog(LogFileName, ' Auto linking is not enabled for this document queue.');

              EXIT;

            END;

            // This gets the items from the queue.

            IF NOT ZdCapture.Refresh THEN

            BEGIN

              WriteToLog(LogFileName, ' Could not refresh the queue.');

              EXIT;

            END;

            QueueItems.RESET;

            QueueItems.SETRANGE(QueueItems." Zetadocs Doc. Queue No." , QueueSettings." No." );

            ProcessAll(LogFileName);

            WriteToLog(LogFileName, 'Zetadocs-Autolink finished.');

          END;

  }

  CODE

  {

    VAR

      QueueSettings@1000000000 : Record 9009989;

      QueueID@1000000002 : Code[20];

      ZdUtilities@1000000005 : Codeunit 9009959;

      QueueItems@1000000006 : Record 9009998;

      ZdCapture@1000000004 : Codeunit 9009970;

    PROCEDURE ProcessAll@1000000003(LogFileName@1000000000 : Text[250]) result : Boolean;

    VAR

      tmpQueueItemRec@1000000001 : TEMPORARY Record 9009998;

      queueCount@1000000002 : Integer;

    BEGIN

      // We loop through the queue items, autolinking them.

      IF QueueItems.FIND('-') THEN

      BEGIN

        REPEAT

          WriteToLog(LogFileName, STRSUBSTNO(' Processing queue item: %1', QueueItems." Document Key" ));

          IF NOT (QueueItems.Locked) THEN

          BEGIN

            tmpQueueItemRec.DELETEALL(FALSE);

            tmpQueueItemRec := QueueItems;

            tmpQueueItemRec.INSERT;

            // We call process on the queue item, making sure UIEnabled is set to FASLE

            IF NOT ZdCapture.Process(tmpQueueItemRec,FALSE) THEN

            BEGIN

              WriteToLog(LogFileName, '  Processing failed.');

              // Unlock the file if it has been locked

                tmpQueueItemRec.FIND('=');

                ZdCapture.Release(tmpQueueItemRec);

              // If we run into any problems we see if the stop batch processing flag has been set.

              // If not then just continue to the next queue item.

              IF ZdCapture.GetStopBatchProcessing THEN

              BEGIN

                WriteToLog(LogFileName, '  Stop batch processing flag set while processing this queue item.');

                EXIT(FALSE);

              END;

            END

            ELSE

            BEGIN

              WriteToLog(LogFileName, '  Processing successful.');

            END;

        END

        ELSE

        BEGIN

          WriteToLog(LogFileName, '  Could not process this queue item as it is locked.');

        END;

        UNTIL  QueueItems.NEXT = 0;

      END;

      EXIT(TRUE);

    END;

    PROCEDURE WriteToLog@1000000000(LogFileName@1000000000 : Text[250];LogLine@1000000001 : Text[250]);

    VAR

      LogFile@1000000002 : File;

    BEGIN

      IF EXISTS(LogFileName) THEN

        BEGIN

          LogFile.WRITEMODE:=TRUE;

          LogFile.TEXTMODE:=TRUE;

          LogFile.OPEN(LogFileName);

          LogFile.SEEK(LogFile.LEN);

        END

      ELSE

        BEGIN

          LogFile.TEXTMODE:=TRUE;

          LogFile.CREATE(LogFileName);

        END;

      LogFile.WRITE(STRSUBSTNO('%1 %2', CURRENTDATETIME, LogLine));

      LogFile.CLOSE;

    END;

    BEGIN

    END.

  }

}

References

Zetadocs for NAV Installation Guide, section 15.6.

Last updated: 13th April 2011 (LD/MW)

EquisysLogo

Recent news

It’s that time of year again. Directions EMEA is right around the corner. This year, it takes place at the Austria Center in Vienna, between 9-11 October. Traditionally, Directions NA would take ...

We are delighted to announce that the Zetadocs Delivery and Zetadocs Capture Extension for Business Central is now available on AppSource, the app store for Business Central. This is an ...