Equisys technical notes

Technical guidance, explanations and fixes for our products

HOWTO: Use Zetadocs for NAV Delivery Plus to send additional related documents stored in SharePoint or Zetadocs Archive

Print

ZTN4105

ID: ZTN4105

This Zetadocs technical note applies to:

  • Version 4.0 and later of Zetadocs for NAV

Summary

This article demonstrates how you can use the Zetadocs for NAV Delivery Plus WriteAdditionalEmbCommsToFile function to fetch additional related documents from SharePoint or Zetadocs Archive which are then combined with the printed NAV report into a single PDF. This will then be sent to the NAV recipient.

Note: The interface of this function has changed for version 7.0 of Zetadocs for NAV.

Out of the box you can use Zetadocs templates to attach common documents like Conditions of sale and purchase, however in order to attach documents related to a specific NAV record, you’ll need to implement business logic in Codeunit 9009962: Zetadocs-Send Customize. This is useful where there are supporting documents like Work specification drawings or RFPs that need to be sent with to the Quote, Order or Invoice.

The code in this article shows how to retrieve a previously archived document in SharePoint based on some metadata, in this case the unique ID for the Order Confirmation. This metadata is created by Zetadocs, but the logic can be extended to incorporate your document structures within NAV or outside of NAV as long as the documents to be attached are already in PDF format and accessible to the Zetadocs client.

Zetadocs Delivery Plus is a chargeable add-on to Zetadocs Delivery Essentials.

More information

Version 6.0 and later of Zetadocs for NAV

Codeunit 9009962: Zetadocs-Send Customize contains an example of how to how to add the external document number as an additional dynamic field when sending an invoice with Zetadocs.

  1. If you are using ZDNAV 8.0 or earlier, download the updated Zetadocs-Send Customize and Zetadocs-Archive codeunits from ZTN4105 and follow the installation instructions.
  2. From the Object Designer, open Codeunit 9009962: Zetadocs-Send Customize
  3. Scroll to the WriteAdditionalEmbCommsToFile trigger.
  4. Uncomment the block comment in the function.
  1. Save and Compile the Codeunit.

Version 5.5 of Zetadocs for NAV or earlier

Before following the steps, please note that there is only one option for archiving for this version which is SharePoint.

  1. From the Object Designer, open Codeunit 9009962: Zetadocs-Send Customize
  2. In the Trigger: WriteAdditionalEmbCommsToFile create the following C/AL Local Variables

Name

DataType

Subtype

Length

EmbComms

Text

1024

ZdArchive

Automation

'Zetadocs Dynamics Utilities DLL'.ZdExtArchive

ZdArchiveDocs

Automation

'Zetadocs Dynamics Utilities DLL'.IZdArchiveDocs

documentToMatch

Automation

'Zetadocs Dynamics Utilities DLL'.ZdArchiveDoc

metadataFields

Automation

'Zetadocs Dynamics Utilities DLL'.ZdMetadata

index

Integer

ZdArchiveDoc

Automation

'Zetadocs Dynamics Utilities DLL'.IZdArchiveDoc

metadataToMatch

Automation

'Zetadocs Dynamics Utilities DLL'.ZdMetadata

ArchiveIDToMatch

Automation

'Zetadocs Dynamics Utilities DLL'.ZdMetadataItem

Mail

Codeunit

SMTP Mail

EmailBody

Text

1024

RecRef

RecordRef

ShipmentNo

Code

10

OrderNo

Code

10

fRef

FieldRef

ArchiveID

Text

100

ZdAutomation

Codeunit

Zetadocs-Automation

  1. In the Trigger: WriteAdditionalEmbCommsToFile paste the following C/AL Code. Please read through the code and comments to understand the process.

// Write out any embedded commands to the file using the format:

// file.addCommand('%%[EmbeddedCommand: Value]');

  // Create the ZdArchive object

CASE ZdSendSettings."Report ID" OF

  9009962: //Zetadocs-Order Confirmation

    BEGIN

      ZdAutomation.CreateZdExtArchive(ZdArchive);

      ZdArchive.Initialize('sharepoint: ' + ZdUtilities.GetSharePointSite);

      // Create an archive document to use with matching

      ZdAutomation.CreateZdArchiveDoc(documentToMatch);

      // Create an object to store the metadata fields to return

      ZdAutomation.CreateZdMetadata(metadataFields);

      // Create a metadata field to store the archive id

      ZdAutomation.CreateZdMetadataItem(ArchiveIDToMatch);

      IF(ISCLEAR(ArchiveIDToMatch)) THEN

        ERROR('Failed to create metadataitem');

      ArchiveIDToMatch.Name := 'ZetadocsArchiveID' ;

      ArchiveID := ZdSendResult."Zetadocs Archive ID";

      ArchiveIDToMatch.value := ZdUtilities.TrimGuidBrackets(ArchiveID);

      // Create an object to store the metadata fields to match

      ZdAutomation.CreateZdMetadata(metadataToMatch);

      // Add the archive id metadata field to the fields to match

      metadataToMatch.Add(ArchiveIDToMatch);

      // Add archive id to the list of fields to return

      metadataFields.Add(ArchiveIDToMatch);

      // Set the metadata fields to match in the document object

      documentToMatch.Metadata(metadataToMatch);

      // Set the current folder to the name of the document library to search

      ZdArchive.CurrentFolder := 'Archive';

      // Call GetDocuments to get the list of matching documents from sharepoint

      ZdArchiveDocs := ZdArchive.GetDocuments(documentToMatch, metadataFields);

      FOR index := 0 TO ZdArchiveDocs.Count - 1 DO

      BEGIN

        ZdArchiveDoc := ZdArchiveDocs.Get(index);

        //Write out extra embedded commands to file

        file.addCommand(STRSUBSTNO('%%[Fileattachment: %1]', ZdArchiveDoc.FileUrl) + '\^^');

      END; 

    END;  //9009962

  END;

  // Clear the objects we created

  CLEAR(ZdArchiveDoc);

  CLEAR(ZdArchiveDocs);

  CLEAR(metadataFields);

  CLEAR(metadataToMatch);

  CLEAR(documentToMatch);

  CLEAR(ZdArchive);

ZdAction := ZdAction::Continue;

  1. Modify the code to implement your own logic for adding the links.
  2. Save and Compile the Codeunit.

Test your system

You are now ready to test your work.

  1. Ensure you have a related document against the Sales Order which you are going to print. Note in the example above the code will only fetch document linked to Sales Orders.

  1. Print the report to Zetadocs and preview it in the Zetadocs Client.
  2. You should now see additional document in the report preview.

References

Use the Zetadocs for NAV Installation guide for further details on the functions used in this article.

Last updated: 1st April 2016 (GC/MW/JV/NT)

Equisys Logo, Document Management and Expense Management for Business Central
 

Replaced by script