Create Word Document from SharePoint List with MS Flow & Quick Parts

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, their 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 in a separate Document Library on the SharePoint Site.

Document Library

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 is 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.
    Generated document

The overall procedure is mentioned in the 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.
    Different document library

At the end of this article, we will convert the document template to the proper documents.

Document template

Now, let’s get started!

Step 1. Create Site Columns

  • To create a list and document library structure, first, create Site Columns for 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.
     Site Settings
  • Click on the Create button.
  • Give the Column name and click the Ok button.
  • We created three site columns and add to our custom group named “HR Data”.
    HR Data

Step 2. Create a List and Library.

  • Create a Custom List named “Offer Letter Data”.
  • Add three Site columns to the list.
    Offer Letter Data
  • Create a Document Library named “OfferLetterTemplate”.
  • Add three Site columns to the library.
    OfferLetterTemplate
  • Create a Document Library named “OfferLetters”.
  • Add three Site columns to the library.
    OfferLetters

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.
    Word document
  3. Click on Open in Desktop App.
    Desktop App
  4. From Pop Up, click on the Open Word button.
    Open Word button
  5. Type your content.
    Content
  6. To add the Quick Parts, Go to the Insert > Quick Parts > Document Property. Set the Document Property in your Document.
    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.
    Automated Flow
  3. Give the Name of the Flow and Triggering Action.
    Triggering Action
  4. In the first step > Add the Site Address and List Name.
    Add the Site Address
  5. Second Step
    • Add an Action > Get file Content.
    • Add the 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”.
      Get file Content
  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 the file name as “EmployeeName”.docx.
    • Pass File Content from the Get File Content section.
      Create a file
  7. Step 4
    • Update file Properties,
    • Here, we will update the file properties for the OfferLetters library.
    • Id = ItemId from the Create file section.
    • Date of Joining, Employee Name, and Salary Appropriate field from When an item is created section.
      Update file Properties
    • The overall flow will look like in the following screenshot.
      Overall flow

Now, It’s time for testing.

  1. Add a new Entry in the Offer Letter Data list.
    Offer Letter Data list
  2. The flow will trigger.
    Trigger
  3. The document will be stored in the OfferLetters document library.
  4. Click on the ellipses icon and click on the Preview document.
    Preview document
  5. Here, you can see replaced values.
    Replaced values

Note. The created Word document will not work with Word Online Edit mode. The reason is, that Quick Parts only supports the desktop version of the 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 documents from the document template using MS Flow. I hope you love this article! Stay connected with me for amazing MS Flow Articles.


Similar Articles