for Microsoft Power Automate and Azure logic apps

Mail Merge a Word Document with a Microsoft Forms Response

By Jay Goodison

4th June 2021

Mail Merge a Word Document with a Microsoft Forms Response

When you think of our new Populate Word Document action, you might not think to mail merge a Word Document with a Microsoft Forms Response, but that’s why we’re here. To inspire you!

We are excited to release our new ‘Populate Word Document‘ action, enabling you to populate Microsoft Word Documents with data quickly!

Over the next few weeks, we’ll release several posts covering everyday use case scenarios for this action; for this post, we’ll provide a detailed demonstration for adding data from a Microsoft Forms response to a Microsoft Word document.

Create a Word Document from a Microsoft Forms Response

I have previously created a simple Microsoft Form containing several questions:

Now let’s create a flow to make a Word Document containing the details of each response provided.

1. Create a new Flow using the ‘Automated cloud flow‘ option

2. Enter a name for the Flow, select the ‘When a new response is submitted‘ Microsoft Forms trigger action and click ‘Create.

3. Select the Form

4. Add the ‘Get response details‘ Microsoft Forms action

4.a. Form Id: Select the same form as selected in step #3

4.b. Response Id: Select the ‘Response Id‘ property provided by the ‘When a new response is submitted‘ Microsoft Forms trigger action

We now have access to all of the data for the relevant response. We need to configure the Microsoft Word document so that the Encodian ‘Populate Word Document‘ action can add the response data.

I have configured the source Word document as follows:

The syntax and capabilities of the Encodian ‘Populate Word Document‘ action are documented here: Template Syntax for Populate Word Document.

I have added ‘Token’ as a placeholder for each element of the response I wish to add to the document; the syntax is as follows:

<<[propertyName]>> 

For example:

<<[submittedBy]>>

When the Encodian population runs, it will locate all of the tokens within the document and then attempt to replace them with the data provided. So let’s set this up!

The Encodian ‘Populate Word Document‘ action requires two parameters; the document we’ll pull from SharePoint for this example and the data.

5. Add and configure a SharePoint ‘Get file content‘ action or similar to obtain the template document.

6. Add the Encodian ‘Populate Word Document‘ action

6.a. File Content: Select the ‘File Content‘ property provided by the ‘Get file content‘ action

Now, we need to pass data to the Encodian ‘Populate Word Document‘ action, which will be used to replace the configured tokens. The data is formatted as JSON and follows this simple schema:

{
   "tokenName":"Value"     
}

The example document I have contains several tokens, and I’ve structured the JSON as follows:

{
   "submittedBy":"",
   "submittedOn":"",
   "satisfaction":"",
   "needs":"",
   "rating":"",
   "responsiveness":"",
   "time":"",
   "future":"",
   "recommend":"",
   "comments":""
}

This screenshot depicts the relationship between a token name and the JSON property name:

6.b. Add the JSON structure to the ‘Document Data‘ field

6.c. Using dynamic data provided by the Microsoft Forms ‘Get Response Details‘ action, map to the JSON data set as follows:

Upon completion, your configuration should look similar to:

The Encodian ‘Populate Word Document‘ action returns a DOCX document with the data populated; for this example, we’ll email the document to the submitter.

7. Add a ‘Send an email notification (V3)‘ action

7.a. To: Select the ‘Responders Email‘ property from the Microsoft Forms ‘Get Response Details‘ action

7.b. Configure the Subject and Body properties as required

7.c. Attachment: Select the ‘File Content‘ property provided by the Encodian ‘Populate Word Document‘ action

7.d. Attachment File Name: Either manually add a name or use the Encodian ‘Filename’ property which will always be set to ‘result.docx’. I have manually set the filename for this example.

The flow is now complete and should follow this structure:

We recommend reviewing the following article, which will help how errors are reported during the creation of your solution: Error Handling.

Test your form by submitting a new response to the Microsoft Form; your flow should execute as follows:

As the responder, you should have received an email:

The attachment should contain a word document populated with the results of your response:

Finally…

Hopefully, this post provides an excellent example of using the Encodian ‘Populate Word Document‘ action to add data to a Microsoft Word document; please share any feedback or comments – all are welcome!

Leave a comment

Your email address will not be published.