Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

In this article, we will learn about two important concepts (Quick Parts and MS Flow) to generate the Word document using existing Word Template. During this article, we will read the Word document from a SharePoint Document Library, and replace the Quick Parts Values with SharePoint List Item value. Once the value is replaced, we will store the document in another Document Library.

Overview

 
We have come across the following real-life scenario in which we need to generate the Offer Letter for every new joiner in the organization using the predefined values.
 
Whenever a new person is selected, its entry will be added to the SharePoint list. We trigger the flow upon the new item creation. First, we need to read the Word template with Quick Parts values and then we will replace the Quick Parts values with the fetched SharePoint list item value. In the end, we will store the generated Offer Letter to a separate Document Library in SharePoint Site.
Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts
So basically, it’s a Trio – SharePoint Word Template – MS Flow – and SharePoint Word Document creation in a separate library.
 
Example
 
We have the following three lists,
  1. Offer Letter Template – Whenever a new person will be selected, their entry is added to this list.
  2. Offer Letters – The predefined word template will be stored here.
  3. Offer Letters – The Generated document for each new joiner will be stored in this document library.
Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts 
 
The overall procedure is mentioned in below step by step chart.
  • MS Flow will read the Word Template stored in one of the Document Library
  • Quick Parts are replaced with the fetched Value from the SharePoint list
  • A newly created Word Template will be stored in a different document library.
Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts
 
At the end of this article, we will convert the document template to the proper documents.
 
Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts
 
Now, let’s get started!
 
Step 1 - Create Site Columns
  • To create a list and document library structure, first, create Site Columns to your site collection. The reason is, if we create a list column or library column, it will not replace the proper value in the word document.
  • To create a site column, go to Site Settings.
 Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts
  • Click on the Create button.
  • Give Column name and click Ok button.
  • We created three site columns and add to our custom group named “HR Data”.
 Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts
 
Step 2 - Create List and Library
  • Create Custom List named “Offer Letter Data”.
  • Add three Site columns to the list.
Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts
  • Create a Document Library named “OfferLetterTemplate”.
  • Add three Site columns to the library.
Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts
  • Create a Document Library named “OfferLetters”.
  • Add three Site columns to the library.
Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts
 
Step 3 - Create a Word Document Template in the library
 
This is a very important step. Follow the below steps very carefully.
  1. Go to Offer Letter Template Document Library.
  2. From New, Click on Word document.

    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

  3. Click on Open in Desktop App.

    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

  4. From Pop Up, click on Open Word button.

    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

  5. Type your content.

    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

  6. To add the Quick Parts, Go to the Insert > Quick Parts > Document Property. Set the Document Property in your Document.

    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

  7. Save the file and close the file.
Step 4 - Create Microsoft Flow to create a Word Document and Replace Quick Part with List Values
  1. Go here.
  2. Create > Automated Flow

    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

  3. Give Name of the Flow and Triggering Action.

    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

  4. In the first step > Add Site Address and List Name.

    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

  5. Second Step

    Add and Action > Get file Content
    Add Document Library address where we have stored our template. We stored our template in the OfferLetterTemplate library and the name of the template file is – “Software Developer Template”.
    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

  6. Third Step

    Create a file.
    Give the URL for the destination library where we wish to store our documents.
    In the File name, we will assign file name as “EmployeeName”.docx
    Pass File Content from Get file Content section.

    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

  7. Step 4

    Update file Properties,
    Here, we will update the file properties for the OfferLetters library.
    Id = ItemId from Create file section.
    Date of Joining, Employee Name and Salary= Appropriate field from When an item is created section.
    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

    The overall flow will look like in the following screenshot.
    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts
Now, It’s time for testing.
  1. Add a new Entry in the Offer Letter Data list.

    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

  2. The flow will trigger.

     Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

  3. The document will be stored in the OfferLetters document library.
  4. Click on the ellipses icon and click on the Preview document.

    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts

  5. Here, you can see replaced values.

    Generate MS Word Document Consuming SharePoint List Data From A Document Template Using MS Flow And Quick Parts 
Note
The created Word document will not work with Word Online Edit mode. The reason is, Quick Parts only supports the desktop version of Application. You have to open the Word file in Desktop Mode of Word to save any changes.
 

Conclusion

 
This is how we can create Word Document from the document template using MS Flow. I hope you love this article! Stay connected with me for amazing MS Flow Articles.