In Focus

How To Fill SharePoint Metadata In Word Document Template Using Quick Parts And FLOW

In this article, we will see how to generate a document from a Word template, and fill the data dynamically using Quick parts and FLOW.

Scenario

You might have come across a requirement to automate generating documents from templates with some dynamic information filled in automatically. You can do this easily using Quick Parts in a Word document. Quick parts are not new, this has existed for a decade. In this article, we will see how to automate such document generation from Microsoft FLOW.

Solution

In this article, we will see how we can generate a document from the template and fill the content in it dynamically. We will be using the below main steps to achieve it

  1. Read content from a file (read word template)
  2. Create a file (using the above content)
  3. Update properties of the file (of above newly created file) with dynamic values
  4. Return URL of the document to UI (in my case it's PowerApps app)

Generate your document template and store it in SharePoint library

Generate your document template with content inside it. Keep the values to be filled in blank. Upload this document to a document library in SharePoint.

Whatever metadata you want to fill automatically in the document, create those columns in the same document library.

Imp Note: Add these columns to default content type of the library, i.e., Document. To do this from Advanced Settings >> Set “Allow management of content types?” to Yes. Select Document Content type and add from existing list columns.
 

Open this document from SharePoint library >> Edit it in MS Word client.

 
Now, from the Word document top ribbon menu, go to Insert tab >> Quick Parts >> Document Property. You will find the columns created in the SP library. Choose those columns one by one and place those wherever you want in your document template. Save the document (autosave back to the library).
 
 
After inserting all the parts, this is how it looks.
 
 

How to read a document template and fill it in with a dynamic value and create a new document using FLOW

Create a new FLOW or update an existing FLOW. Use any trigger action suitable to your scenario. In my case, it was PowerApps. From PowerApps, I needed to call the FLOW to generate the document.

Add a new action “Get file content”. Select the site, library, and select the template document which we have uploaded/saved in the above steps.

 
Add a new action “Create File” >> Select site, you can choose the same library or different. In the File Content, choose the output of the above action. Enter any name to the file including extension.
 
 
As you have seen, we have created a new document file using our template document. In the next step, we need to update metadata of this file so that it gets automatically filled in the document content.

Add new action “Update File properties”. Then select site, same library as in above action >> in Id field, select ItemId output of the above action.

 
You will see all the metadata columns we created earlier will appear in this action. Now you can fill this information. I have entered fixed content in those. In real time scenario this dynamic data can come from SQL DB, Excel File, User entered values from PowerApps, etc.

We are almost there. Just one last step to add, generate a URL of the document and respond back from where the FLOW is called. In my scenario it's PowerApps. In PowerApps I have used Launch function to download the newly-generated document.

 
Here is an overview of all actions used in this FLOW.
 
 
Done. If you run the flow, now, a document will get generated from the template with filled content in the mentioned library.
 
 
I hope this helps. If you have any questions then please do comment below.