In the last two posts, we explored how to create a Word document with ER. In this final part of the series, I will show you how to fix common issues when working with Word, name the document, and finally export it as a PDF.
Line break
By default, Word deletes line breaks and substitutes them with nothing. We have two options to fix this issue.
Substitute Line Breaks with Spaces
You can use the following simple formula to replace line breaks with spaces:
REPLACE(model.Company.Address,char(10)," ",false)
- The first parameter is the path to the model’s node with the address.
- The second parameter is the char number that the ERP uses for line breaks.
- The third parameter specifies what we substitute line breaks with, in this case, a space.
- The final parameter is
false
because we don’t use regex.
Allow Carriage Returns in Word
You can also configure Word to recognize line breaks for this control. To do this, download the template again, ‘Developer’, select it, go to properties, and enable the “Allow carriage return” option.
Delete placeholder text
When a control doesn’t have any value (the mapping returns blank text), we’ll see the text ‘Click or tap here to enter text.’ For example, if in our legal entity we don’t have a primary phone:
So, we could just add this transformation to all the format’s string nodes, and it would replace empty strings with spaces in most cases:
IF(parameter = "", " ", parameter)
But it won’t work on repeating ranges when there are 0 elements. For example, for an item without variants:
So, a way to fix this is to open the Word template and change the control text to a space (not empty). There was a small problem with this approach, though. Each time I downloaded the template to edit it, the original placeholder text reappeared. However, I cannot reproduce this problem right now, so maybe it has already been fixed.
Now, when running the format, we get:
Give a name to the file
It always looks better if we give a name to the document instead of keeping the original, for example, the item ID and a timestamp:
model.Product.ItemId&"_"&DATETIMEFORMAT(NOW(),"yyyyMMddHHmmssfff")
Convert it to PDF
With ER Destinations, it is easy to convert Word or Excel files to PDF. Let’s complete the format and go to the ER workspace, then to Destinations:
Let’s create a new record and select our format:
Now we add a destination, select our component (in this case, we only have the Word), and check ‘Convert to PDF’:
Finally, go to settings and select a default destination, normally ‘File’ if we want it to download, or ‘Screen’ if we want it to open in a new tab:
Now, when running the format from ER Configurations or integrated into another part of Dynamics, we’ll get a PDF:
Leave a Reply