How to Add Text to Word Templates Before Generating Documents in Dynamics 365

There are many instances when a Dynamics 365 user may want to add some text to a Microsoft Word template before sending a document to a contact.

Templates can easily be personalised to reflect field data including names and addresses but there has been less flexibility to insert bespoke text on the fly before a new document is created.

For example, an extra line or two of text may be beneficial to make a personalised greeting, or to share some additional detail.

Using the new Word Online connector for Microsoft Flow it is now possible to create a flow that reads a Microsoft Word template and then populates the template fields with selected dynamic values to generate a Word document. Best of all, this process can be handled directly within the Dynamics 365 unified interface via an embedded PowerApp that enables additional text to inserted.

In this example, we've created a custom Word template editor PowerApp that references a defined template. 

This control is embedded in the contact form enabling an end user to customise the text that will appear in the opening two paragraphs of this document.

Some sample text is entered into each paragraph box and clicking the 'generate' button will run the Flow.

This will create the document and automatically apply this to the contact timeline. By using another new PowerApp capability, a control can be set to immediately refresh the host form when the document is generated to avoid the need for a manual refresh. 

For this letter, the custom text for these two paragraphs handled by the PowerApp has been applied in addition to the standard name and address detail pulled from the current record.

Within the Flow designer this process is defined to:

  • Trigger the Flow from the PowerApp 'generate document' button
  • Reference the Dynamics contact record 
  • Use the new Word connector to reference a Word template stored in SharePoint
  • Populate a new document with data from the listed contact fields
  • Populate paragraphs 1 and 2 with data entered via the PowerApp letter editor
  • Create a new note record that will be added to the timeline

In this example, we have referenced a contact record to populate template fields but another advantage of Flow compared to a regular Word template is the ability to hop across associated entities. As a result, this can also pull in data fields from a parent Account record.

As an alternative to creating the document in Word, the Flow could be easily adapted to output this as a PDF file. 

At the outset, to create a template in Word select the developer tab and click plain text content control which inserts a control for the merge placeholder. With this initial release of the Word Connector, only plain text is supported so this won't currently enable repeating content controls that are used in tables. 

Finally, this template can be saved in a Sharepoint on OneDrive file where the flow will be able to retrieve it as shown above.

If you want to find out more and deploy a version of this PowerApp with Microsoft Flow within your Dynamics 365 instance please get in touch.  


Receive CRM and Microsoft Dynamics 365 Updates

If you enjoyed this post, why not join our mailing list to receive emails about the latest updates and events from Preact?