HOWTO: Use the Zetadocs for NAV SDK to deliver NAV reports with additional related attachments that are unique to the recipient
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
- From the Object Designer, open Codeunit 9009962: Zetadocs-Customize
- In the Trigger: GetAdditionalEmbComms create the following C/AL Local Variables
- In the Trigger: GetAdditionalEmbComms create the following C/AL Local Text Constants
- In the Trigger: GetAdditionalEmbComms paste the following C/AL Code. Please read through the code and comments to understand the process.
- Modify the code to implement your own logic for adding the links.
- Save and Compile the Codeunit.
Name | DataType | Subtype | Length |
a. Links | Record | Record link | |
b. ZetadocsUtilities | Codeunit | Zetadocs-Utilities | |
c. Path | Text | 250 |
Name | ConstValue |
a. doubleSlash | \\\ (Note: Will become ‘\\’ when you leave Const Value field) |
//
// 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);
You are now ready to test your work.
- 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.
- Run the Zetadocs report, in this case Order Confirmation and select preview.
- 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.
- Next Print the report again but print to the Zetadocs PDF Printer and verify that the link attachments are added to the report document.
e.g. Link ID 9 will not be added.
Figure 1 - Additional Embedded Commands Preview
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)