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.
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.
- Offer Letter Template: Whenever a new person is selected, their entry is added to this list.
- Offer Letters: The predefined word template will be stored here.
- Offer Letters: The Generated document for each new joiner will be stored in this document library.
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.
At the end of this article, we will convert the document template to the proper documents.
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.
- 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”.
Step 2. Create a List and Library.
- Create a Custom List named “Offer Letter Data”.
- Add three Site columns to the list.
- Create a Document Library named “OfferLetterTemplate”.
- Add three Site columns to the library.
- Create a Document Library named “OfferLetters”.
- Add three Site columns to the library.
Step 3. Create a Word Document Template in the library. This is a very important step. Follow the below steps very carefully.
- Go to Offer Letter Template Document Library.
- From New, Click on Word document.
- Click on Open in Desktop App.
- From Pop Up, click on the Open Word button.
- Type your content.
- To add the Quick Parts, Go to the Insert > Quick Parts > Document Property. Set the Document Property in your Document.
- Save the file and close the file.
Step 4. Create Microsoft Flow to create a Word Document and Replace Quick Part with List Values.
- Go here.
- Create > Automated Flow.
- Give the Name of the Flow and Triggering Action.
- In the first step > Add the Site Address and List Name.
- 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”.
- 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.
- 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.
- The overall flow will look like in the following screenshot.
Now, It’s time for testing.
- Add a new Entry in the Offer Letter Data list.
- The flow will trigger.
- The document will be stored in the OfferLetters document library.
- Click on the ellipses icon and click on the Preview document.
- Here, you can see 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.