Add HTML to Docentric Layout

Hi,
I need to add an HTML subDocument to a docentric layout, but I always receive this error when I want to preview result,
image

Unable cast object of type System.Xml.XmlNode to type System.Byte

someone can help me to display and html on the layout.
I have added a new field (EDT: Memo) that contains the html text, then I have added SubDocument with this new field as a Value and Format = HTML

Thank you!
Best regards,

Hi there @HEL, welcome to the Docentric Community!

Would you be able to share your report template with us, along with the DDSP file so that we can check out what could be the issue?

Also, can you share the HTML code that you are trying to use in the Sub Document?

Hi @BlazJ, here are the ddsp, code and the layout
1- field on the tmp table :
image
2- code on the DP class: the HTML code is stored in field from account receivable parameter

3- DDSP attached:
SalesInvoice.ReportFR (5).ddsp (548.9 KB)

4- Layout attached
Facture client FR02 - avec reliquats - Original.docx (319.4 KB)

thank you!

Hi @HEL,

I’ve reviewed your DDSP file and noticed that the problem lies in the INUCGVTxtFR field’s type. It’s currently set as a string, but it should be in binary format, encoded in base64. (type=“xs:base64Binary”).

I have taken your HTML code and used the Base64 converter to get the HTML converted (https://base64.guru/converter)

I have then copied the Base64 value into the DDSP file and changed the type of INUCGVTxtFR field.

image

Once you have the correct data format just reload the DDSP file, and the used Sub Document tagging element should display the data field correctly when the format is set to HTML.

I have loaded the DDSP file into your report template. I am attaching both so you can review the solution.

Facture client FR02 - avec reliquats - Original (Edited by Docentric).docx (324.3 KB)
SalesInvoice.ReportFR (5) (Edited by Docentric).ddsp (552.5 KB)

hi @BlazJ ,

thank you for your reponse,
but I need to know how to convert it in d365 fo X++,
can you help me? witch type of field it should be
image

Thank you!

Hi @HEL,

If I understand correctly, you have an HTML formatted text in the INUCGVTxtFR field in the CustParameters table in the D365FO.
If this is the case, you can try to insert this field value as a calculated field in the Docentric Data Source Package (DDSP).
To do this, you just need to add a few lines of code in the Docentric DSP class of your report.

Here is an example of how we add a child record that contains 2 subdocument fields:

DocXmlRecord subDocumentsDataRecord = _addingRecord.addChildCalculatedRecord('Subdocuments');
str html = "<DIV STYLE='text-align:Left;font-family:Tahoma;font-style:normal;font-weight:normal;font-size:11px;color:#000000;'><P STYLE='font-family:Arial;font-size:12px;margin:0 0 0 0;'><SPAN><SPAN>Ausführung mit:</SPAN></SPAN></P><P><SPAN><SPAN>- Rahmen</SPAN></SPAN></P><P><SPAN><SPAN>mit Sicherheitsschutzgitter und Dichtung Reinluftseitig</SPAN></SPAN></P><P><SPAN><SPAN>Technische Daten:</SPAN></SPAN></P><P><SPAN><SPAN>Filterklasse:F6</SPAN></SPAN></P><P><SPAN><SPAN>Materialrahmen:MDF oder Kunststoff</SPAN></SPAN></P><P><SPAN><SPAN>Bautiefe und Dichtung:292 + 6 mm</SPAN></SPAN></P><P><SPAN><SPAN>Temperaturbeständigkeit:kurzzeitig bis 80°C</SPAN></SPAN></P><P><SPAN><SPAN>Dauerbelastung bis 70°C</SPAN></SPAN></P><P><SPAN><SPAN>Nennvolumenstrom:</SPAN></SPAN><SPAN><SPAN>5.000m³/h</SPAN></SPAN></P><P><SPAN><SPAN>Anfangsdruckdifferenz:135 Pa</SPAN></SPAN></P><P><SPAN><SPAN>Filterfläche:ca. 29,5 m²</SPAN></SPAN></P><P><SPAN><SPAN>Betriebsdruckdifferenz:8 mbar</SPAN></SPAN></P><P><SPAN><SPAN>max. zul. Druckdifferenz:30 mbar</SPAN></SPAN></P><P><SPAN><SPAN>Feuchtigkeitsbeständigkeit:100% RF</SPAN></SPAN></P><P><SPAN><SPAN>LxBxH:610x610x292 mm</SPAN></SPAN></P><P /><P><SPAN><SPAN>Auslieferung ohne Firmenlabel</SPAN></SPAN></P><P><SPAN></SPAN></SPAN></P></DIV>";
str html1 = "<DIV STYLE='text-align:Left;font-family:Tahoma;font-style:normal;font-weight:normal;font-size:11pt;color:#000000;'><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>Ausführung mit:</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>- Rahmen</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>mit Sicherheitsschutzgitter und Dichtung Reinluftseitig</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>Technische Daten:</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>Filterklasse:F6</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>Materialrahmen:MDF oder Kunststoff</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>Bautiefe und Dichtung:292 + 6 mm</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>Temperaturbeständigkeit:kurzzeitig bis 80°C</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>Dauerbelastung bis 70°C</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>Nennvolumenstrom:</SPAN></SPAN><SPAN><SPAN>5.000m³/h</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>Anfangsdruckdifferenz:135 Pa</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>Filterfläche:ca. 29,5 m²</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>Betriebsdruckdifferenz:8 mbar</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>max. zul. Druckdifferenz:30 mbar</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>Feuchtigkeitsbeständigkeit:100% RF</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>LxBxH:610x610x292 mm</SPAN></SPAN></P><P /><P STYLE='font-family:Arial;font-size:12pt;margin:0 0 0 0;'><SPAN><SPAN>Auslieferung ohne Firmenlabel</SPAN></SPAN></P><P STYLE='font-family:Arial;font-size:13pt;margin:0 0 0 0;'><SPAN STYLE='font-size:12pt;'><SPAN> </SPAN></SPAN></P></DIV>";
System.Byte[] htmlInBytes = System.Text.Encoding::UTF8.GetBytes(html);
System.Byte[] htmlInBytes1 = System.Text.Encoding::UTF8.GetBytes(html1);
subDocumentsDataRecord.addCalculatedField('HtmlSubdocument', DocGlobalHelper::convertBytesToContainer(htmlInBytes));
subDocumentsDataRecord.addCalculatedField('HtmlSubdocument1', DocGlobalHelper::convertBytesToContainer(htmlInBytes1));

However, if your custom field does not contain HTML formatted text, you can try adding a calculated field to the DDSP by using the following helper method:

DocGlobalHelper::convertTextToBase64String(str _text)