How-to

Create documents with Power Automate

Tendocs Support

Tendocs Support

Created: Sep 17, 2023 - Updated: Sep 17, 2023

Complete guide, demonstrating how to create new Word Documents based on a template, and any combination of text, images, documents and tables.

Objective

In this example we’ll be achieving the following objective with a fictional organisation named “10docs Ltd”.

10docs is working to professionalise the way they invoice their clients. They have worked on a new Word based Template (Word Invoice Template) that includes their branding, a layout, and the basic content they would like to use.

The template looks like this:

Alt text

Setup

Power Automate is a growing platform, with an enormous number of first and third party connectors. Tendocs works with them all.

To keep it simple, this example uses the following connectors:

  1. SharePoint for Template storage
  2. SharePoint and Excel for Tables
  3. SharePoint and Variables for Text
  4. SharePoint and Variables for Tables
  5. SharePoint for Image and Sub-document storage

If you need any help along the way, feel free to reach out to the support team

Assets

So you can test this yourself, exactly as described here, you can download copies of all the assets used. To get started, all you need is a SharePoint site with a Document Library.

  1. The Company Logo.
  2. The Client Logo.
  3. The Word Invoice Template.
  4. The Excel Invoice Line Items.
  5. the Terms and Conditions document.

In addition to the above, some steps are shown using information from SharePoint Lists. The definition of these will be shared later.

Build

Preparing the basics (Images and Documents)

To keep things simple, we’re going to start with what Microsoft calls an “Instant Cloud Flow”. It means we can run the flow at the click of a button.

  1. Go to the Power Automate home page.
  2. Select “Instant Cloud Flow”, and then complete as follows.

    Alt text

  3. Add a “Get File Content” action to the Flow, and then reference the company logo.

    Alt text

  4. Rename the action to “Company Logo” to make it easier to work with later.
  5. Add another “Get File Content” action, select the “Client Logo. Rename the action to “Client Logo”.
  6. Add another “Get File Content” action, select the “Terms and Conditions” document. Rename the action to “Terms and Conditions”.
  7. Add another “Get File Content” action, select the “Word Invoice Template”. Rename the action to “Word Template”.

The references to the files so far have been static, however, in the case of the client logo, this would be dynamic can come from a “Clients” list, or some other source. You might also have different office templates foe the invoice, and even different company logos. All of this is possible with Power Automate, but beyond the scope of this simple demo.

Preparing the invoice line items (Table)

The invoice line items can be sourced from a number of different places. Tendocs is flexible enough to work with them all. Provided below are common examples to get you started.

  • You can retrieve table information, in this case the invoice line items, directly from a Table in an Excel file. You could do it by having a dedicated file per invoice, or, by performing a dynamic filter using the capabilities provided by the Excel connector.

    1. Add the “List rows present in a table” Excel (Business) action, select the SharePoint Site, Document Library, and then the Excel File. Choose the “InvoiceLines” table, and then for example add a filter to retrieve only those items for a specific invoice.

      Alt text

    2. Rename the action to “Invoice Line Items”.

  • You can retrieve table information, in this case the invoice line items, directly from a SharePoint List. In most cases this would require you to filter the items by Invoice Number to get only those you need, a capability provided by the SharePoint connector.

    1. Create a Custom SharePoint List in your SharePoint site.
    2. Create a new column for each of the line item columns that exist in the document. The column names need to exactly match the tokens in the template.
    3. Create sample data.
    4. An example would look like this:

      Alt text

    5. Add the SharePoint “Get Items” action, select the SharePoint site, and the list created in the step above. You can also filter the list if required.

      Alt text

    6. Rename the action to “Invoice Line Items”.
  • The most flexible, but also the most advanced option is to create your own JSON asset. In this case you would need to pass in an array of object, with each object representing a row in a table (an Invoice Line Item). PowerAutomate has some good features for working with JSON, and arrays (or collections).

    1. Add a new “Compose” action, then paste in a JSON based array that matched the tokens in the template.

       [
         {
           "Title": "Line1",
           "Description": "Line Item 1",
           "Amount": 100,
         },
         {
           "Title": "Line 2",
           "Description": "Line Item 2",
           "Amount": 200,
         },
         {
           "Title": "Line 3",
           "Description": "Line Item 3",
           "Amount": 300,
         }
       ]
      
    2. The action finished action should look like this:

      Alt text

    3. By supporting JSON in this way, you can create tables to dynamically insert into your documents from just about anywhere.

Preparing the simple text replacements (Text)

The most common feature of a template is being able to replace simple text values. These too can be sourced from a number of different places. Tendocs is flexible enough to work with them all. Provided below are common examples to get you started.

  • You can retrieve text replacement information from a Table in an Excel file. It could be a dedicated file, but more likely one with a table containing information about all invoices which is filtered using the capabilities provided by the Excel connector.

    1. Add the “Get a row” Excel (Business) action, select the SharePoint Site, Document Library, and then the Excel File. Choose the “Invoices” table, and then select “ID” for the “Key Column” and 1 for the “Key Value”.

      Alt text

    2. Rename the action to “Invoice Details”.

  • You can retrieve text replacements directly from a SharePoint List Item. You will need to have some way to identify which List Item in a SharePoint List is related to this client, for example via a filter operation, or the List Item ID. These are capabilities provided by the SharePoint connector.

    1. Create a Custom SharePoint List in your SharePoint site.
    2. Create a new column for each of the replacement token that exist in the document. The column names need to exactly match the tokens in the template.
    3. Create sample data.
    4. An example would look like this:

      Alt text

    5. Add the SharePoint “Get Item” action, select the SharePoint site, the list created in the step above and then an item ID.

      Alt text

    6. Rename the action to “Invoice Line Items”.
  • The most flexible, but also the most advanced option is to create your own JSON object. In this case you would need to pass a single object with each property matching the text replacement token in the document. PowerAutomate has some good features for working with JSON onjects.

    1. Add a new “Compose” action, then paste in a JSON based array that matched the tokens in the template.

       {
         "CompanyName":"10doocs",
         "CompanySlogan":"Delivering stuff you didn't expect",
         "CompanyStreetAddress":"1 Documentation Road",
         "CompanyCity":"Small Town",
         "CompanyPostcode":"3455",
         "CompanyWebsite":"www.10docs.com",
         "InvoiceNumber":"1000001",
         "InvoiceDate":"01/01/01",
         "InvoiceDescription":"Invoice for lots of work done",
         "InvoicePurchaseOrder": "9999999",
         "InvoiceToName":"Joost van Hoorn",
         "InvoiceToCompany":"VIP Customer Ltd",
         "InvoiceToAddress":"101 Client Office Road",
         "InvoiceToCity":"Big Town",
         "InvoiceToPostCode":"4533"
       }
      
    2. The action finished action should look like this:

      Alt text

    3. By supporting JSON in this way, you can build up the object required to dynamically replace text in your documents from just about anywhere.

Putting it all together with the Tendocs action

The previous steps have completed all the preparation necessary to automate the creation of invoices.

  • Both the company and client logos have been retrieved.
  • The Word Template have been retrieved.
  • The document that contains the Terms and Conditions has been retrieved.
  • The Invoice Line Items have been sourced from three possible locations.
  • The Invoice Details have been sourced from three possible locations.

The next and most important step is to put it all together using the Tendocs Documents action.

  1. Add the Tendocs “Create New Document from Template” action.
  2. The first time you add the action, you will also need to establish a new “Connection”.
    1. The new connection screen will look like the following: Alt text
    2. Enter a new name for the connection, so that you can identify it later.
    3. The API key should come from the “Profile” page on the Tendocs website, after following the “Sign up” instructions.
    4. When complete, click on “Create”.
  3. Expand the “Show Advanced Options” link to show the following:

    Alt text

  4. Complete the fields as follows:
    1. Template File: “Word Template” - “File Contents”
    2. Text: “Invoice Details” - “Body”
    3. Image Token 1: “CompanyLogo”
    4. Image File Content: “Company Logo” - “File Contents”
    5. Add another image by clicking “+ Add new item”
    6. Image Token 2: “InvoiceToLogo”
    7. Image File Content: “Client Logo” - “File Contents”
    8. Document Token 1: “TermsAndConditions”
    9. Document File Content: “Terms and Conditions” - “File Content”
    10. Table Token 1: “InvoiceLines”
    11. Table Rows 1: “Invoice Line Items” - “Body - List of Items”.
      • Important: Be sure to select the “Body - List of Items” and not “Value - List of Items”.
    12. Document Format: Select the format for the document “Original”.
    13. Configuration Keys: Provides for advanced configuration scenarios.

Saving the new document

The final step is to connect an action to save the document to the location we want to store it.

  1. Add the SharePoint “Create File” action.
  2. Select the destination SharePoint site, then a Folder Path. You will need to set a filename, which will most likely require some logic to avoid overwriting other generated documents.
  3. In the “File Content” section, add the “File Content” from the Tendocs Action. Alt text

Running the new Flow to create your document

All the pieces are now in place, all that is left is to test the new flow.

  1. After saving the Flow, click on the “Test” button, select “Manually” for the trigger, and then click “OK”. You may be prompted to check or create connections, where you can “Continue” and then “Run Flow”.
  2. After a short period of time, the Flow should complete successfully, and you will find the document created with all the merged information.

The Final Result

The final result is a brand new document that is the combined result of the Word Template provided, the Images, Tables, Documents and Texts.

Alt text

Download the document to see for yourself.

Previous
Sign up for a new subscription
Next
Change your current plan