Equisys technical notes

Technical guidance, explanations and fixes for our products

HOWTO: Use the Zetadocs for NAV SDK to deliver NAV reports with additional related attachments that are unique to the recipient

Print

ZTN4019

ID: ZTN4019

This Zetadocs technical note applies to:

  • Zetadocs for NAV v1.2
  • Microsoft Dynamics NAV 5.0

Summary

This article demonstrates how you can use the Zetadocs for NAV SDK’s GetAdditionalEmbComms function to return additional documents which are combined with the printed NAV report into a single PDF. This will then be sent to the NAV recipient.

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 only related to a specific NAV record, you’ll need to implement business logic in the Zetadocs for NAV SDK. 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 focuses on related PDF documents referenced in the NAV Record links table, but the logic can be extended to incorporate your document structures within NAV as long as the documents to be attached are already in PDF format and accessible to the Zetadocs client.

The Zetadocs for NAV SDK is a chargeable add-on to Zetadocs.

More information

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


  3. NameDataType  Subtype  Length
    a.  LinksRecordRecord link
    b.  ZetadocsUtilitiesCodeunitZetadocs-Utilities
    c.  PathText250


  4. In the Trigger: GetAdditionalEmbComms create the following C/AL Local Text Constants


  5. NameConstValue
    a.  doubleSlash  \\\         (Note: Will become ‘\\’ when you leave Const Value field)


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

    // We can use the parameters to check for conditions on adding the links attachments

    // in this case we only add for report 9009962

    //

    CASE ZdSendSettings." Report ID" OF

      9009962: //Zetadocs-Order Confirmation

        BEGIN

          //

          //Look up links from table

          //

          Links.SETFILTER(" Record ID" ,  FORMAT(Record));

          //

          //If any links to add

          //

          IF Links.FIND('-') THEN

            REPEAT

              //

              //Network file - links prefix with 'file://'.This disrupts Zetadocs so it must be removed.

              //Local file - These fine but realise they will not be available to other users on a different machine

              //Internet URLs - are not supported by the Zetadocs Attachments command and should be filtered out if you are storing

              //any in your links.

              //

              Path := Links.URL1;

              IF NOT ( STRPOS(Path, 'file://') = 0) THEN

                BEGIN

                  //

                  //Get Path without 'file://' prefix

                  //

                  Path :=  COPYSTR(Path, 8);

                END;

              //

              //If network path '\\' then need to remove it and re-add it.

              //This is a work around for writing '\\' onto a report without getting 2 newlines.

              //FormatPathForOutput - replaces '\' with '\\' to give valid path to Zetadocs.

              //

              IF (Path[1] = '\') AND (Path[2] = '\') THEN

                BEGIN

                  //If its a network path we have to manually add the double slash

                  Path := COPYSTR(Path, 3);

                  Path := ZetadocsUtilities.FormatPathForOutput(Path);

                  Path := DoubleSlash + Path;

                END

              ELSE

                BEGIN

                  Path := ZetadocsUtilities.FormatPathForOutput(Path);

                END;

              //

              //Finally write the embedded command

              //NOTE: You may want to check the file extensions to ensure only .pdf or .zda files are passed to Zetadocs

              //as these are the only supported file types for the Attachment command.

              //

              commands := commands + '%%[Attachment:' + Path + ']' + '\';

            UNTIL Links.NEXT = 0;

        END; //9009962

    END;

    ZdAction := ZdAction::Continue;

    EXIT(commands);

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

You are now ready to test your work.

  1. Add links to a record for which your chosen reports will print. Note: In the example above the code will only pull attachments linked to the Sales Header and not the Sales Lines.
  2.  

    e.g. Link ID 9 will not be added.

  3. Run the Zetadocs report, in this case Order Confirmation and select preview.
  4. You should now see additional embedded commands in the report preview for each of the associated links. Note the second group of embedded commands in the middle of the page. These are the additional embedded commands.

  5. Figure 1 - Additional Embedded Commands Preview

  6. Next Print the report again but print to the Zetadocs PDF Printer and verify that the link attachments are added to the report document.

References

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

Last updated: 26 September 2008 (GC/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 ...