Docentric gives you the ability to generate electronically signed reports from D365FO. But what if you email your reports and use another feature provided by Docentric, sending the additional report attachments? The report document will be electronically signed, but the additional attachments won’t. What should be done to send emails with all attachments signed? In this article we will show you how to make small adjustments in the code to send emails with signed attachments.
To demonstrate how this solution works, we will describe the following:
- Docentric report setup and customized DSP class,
- Electronic signature setup,
- Docentric Email print destination setup.
Docentric report setup and customized DSP class
We will use the Sales invoice report for this example. Instead of the Docentric replica DSP class for Sales invoice, we have implemented a new DSP class named DocSalesInvoiceWithSignedAdditionalAttachmentsDSP which inherits from the DocSalesInvoiceReportDSP class. We have selected that class in the Docentric report setup:
In this new class, we have overridden a method loadReportAttachments() and added the logic to electronically sign all additional email attachments:
- We first call super() to make sure that all additional email attachments are loaded based on the Additional attachment rules setting in Docentric Email print destination.
- The logic that follows after super() iterates through all loaded additional email attachments, applies electronic signature to the them, and at the end replaces the attachments from the pipeline with signed attachments.
Here is the code from our implementation:
container attachedDocument, attachedDocumentContent;
public void loadReportAttachments(DocReportRunContext _reportRunContext)
// load signature appearance settings if needed
container additionalAttachments = _reportRunContext.emailPrintDestSettings().parmEmailAdditionalAttachments(); // input container with unsigned attachments
container additionalAttachmentsSigned; // output container with signed attachments
// Iterate through the additional attachments.
// They are stored in a container in this way:
// [ [attachmentName, [content]], [attachmentName, [content]], ...]
for (counter = 1; counter <= conLen(additionalAttachments); counter++)
attachedDocument = conPeek(additionalAttachments, counter);
// Get the content of the attached file and sign it
attachedDocumentContent = conPeek(attachedDocument, 2);
attachedDocumentContent = DocGlobalHelper::convertMemoryStreamToContainer(
// In the current attachment document, replace the original content with the signed content
attachedDocument = conPoke(attachedDocument, 2, attachedDocumentContent);
// Add the signed document to the container with signed attachments
additionalAttachmentsSigned = conIns(additionalAttachmentsSigned, counter, attachedDocument);
// If there were any attachments, replace the original additional attachments container
// with the new one having the signed documents
if (conLen(additionalAttachments) > 0)
Electronic signature setup
Docentric Electronic Signature setup > PDF Security for the Sales invoice report is shown in the image below:
Learn how to setup Electronic Signatures within Docentric >>
Docentric Email print destination setup
The next step is to set up the Docentric Email print destination to attach the documents as additional email attachments. For this example, we will use the Terms & Conditions (T&C) document that is stored as a document management attachment on the legal entity.
Docentric Email print destination settings:
In the Additional attachment rules section of the Docentric Email print destination we set the rule to load the Terms and Conditions document and add it to the email as an additional attachment:
Learn more about the Report attachments >>
Finally, after we have made all the necessary settings, let us print a Sales invoice report and check the email attachments. Since we have enabled the Open email before sending option, we can open the .eml file and review email attachments.
The email downloaded from the browser contains 2 attachments:
- Sales invoice report,
- Terms and Conditions document as an additional attachment.
When we open the Sales invoice report with a PDF viewer, we can see that the report has been successfully signed:
The electronically signed report was the expected result, but what about the additional email attachment document? Let us open it in PDF Viewer and check it:
That’s it! Our additional email attachment is successfully signed.
Simple, isn’t it?