When you want to embed a document or HTML to the report, you can use the Subdocument tagging element. This element can only be used with MS Word documents and HTML.
Both of these file types can be uploaded to D365 as attachments and subsequently used in Docentric templates.
Since the Subdocument tagging element expects a binary data type you will need to encode the Word document/HTML accordingly in the custom DSP class. Here is the example code snippet where we encode the hardcoded HTML and add it to the data-source as a calculated field:
DocXmlRecord subDocumentsDataRecord = _addingRecord.addChildCalculatedRecord('Subdocuments');
str html = "<div style='text-align:Left;font-family:Tahoma;font-style:normal;font-weight:normal;font-size:12px;color:#000000;'><p style='font-family:Arial;font-size:12px;margin:0 0 0 0;'><span>Boost your efficiency</span></p><p><span>Up to 10x faster report customization in MS Dynamics 365 for Finance and Operations and Dynamics AX 2012.</span></p><p><span>Enhance SSRS - Enhance reports such as Invoices and Orders in terms of design and printing.</span></p><p><span>Improve Print Destinations - Improve the way you email, print and archive your reports – for free</span></p><p><span>Design in MS Word All your forms including Invoices, Orders, Quotes, Checks and Labels</span></p></div>";
System.Byte[] htmlInBytes = System.Text.Encoding::UTF8.GetBytes(html);
subDocumentsDataRecord.addCalculatedField('HtmlSubdocument', DocGlobalHelper::convertBytesToContainer(htmlInBytes));
We would use similar approach if we wanted to encode the document fetched from the D365 attachments.
To start using the custom DSP class that contains the logic for fetching and encoding the fields, do not forget to select it as the DSP (Data source provider) class in the Docentric report setup.
This is how the binary content will look like in the data-source:
Now we can bind this field to the Subdocument tagging element and choose between two available formats, Word Document (.docx) or Html depending on the source:
In cases where you have multiple subdocument records inside the data-source, you can either reference the one you need using square brackets:
CurrentCompany/Subdocuments[1]/@HtmlSubdocument
This expression will return the
@HtmlSubdocument
field only from the first Subdocuments record.
Or use a Subdocument tagging element within a List tagging element and have all subdocuments listed respectively.
Encode HTML content to binary within the template
While the Word document needs to be encoded in the DSP class, you can encode the HTML content in the template by using get-string-binary()
XPath function. This function encodes the given string by using the UTF-8 encoding and returns the binary result in the form of a Base 64 string.
Your HTML needs to have HTML escape character equivalents instead of angle brackets in the data source due to the XML syntactic rules (See W3C Extensible Markup Language (XML) 1.0 (Second Edition), Chapter 2.4, Page 9). This entails that, for example, instead of having
<B>
you would need have<B>
.
When you have properly formatted HTML in the data-source:
You can use the expression below to display the HTML using Subdocument tagging element:
get-string-binary(SalesConfirmLines/ExtensionFields/@HtmlContent)