Jessie Does Power Platform

Dataverse: Autogenerating populated document templates

These instructions assume that you already have an Excel or Word template created for your solution. These examples can be used to auto‑generate a filled template as part of an existing process, such as sending a confirmation document upon submission. I've added a few extra steps into the flow information to allow for dynamically grabbing the environment URLs, but there are other ways to accomplish these as well.

Get Template Information | Word Templates | Excel Templates

Assumptions / Prerequisites

Get Template Information

Go to the environment where your solution exists and open the Maker Portal home page.

Launch the Power Platform Environment Settings app.

2339822408-Step-1

In the left navigation, select Templates.

1984445370-Step-2

Select Document templates.

1173942912-Step-3

Select your template name to open its form.

Step4-DocTemplate

Copy the full URL from the address bar.

2584293685-Step-5

Store this URL—you will need the GUID after id= for your flow.

1839844182-Step-6

Word Templates

Word templates operate on a single Dataverse item. The following example automatically generates a confirmation document when an item is approved and uploads that document to the timeline.

This flow is being triggered by a change to a Dataverse table - it is one of many options for triggering this kind of process.

2666449547-WordTemplateFlow-Step-1

Get the Dataverse row by ID. This allows retrieving the environment URL dynamically rather than hard coding it into a flow.

3568235291-WordTemplateFlow-Step-2

Add a Compose action with the expression:

concat('https://', uriHost(body('Get_a_row_by_ID')?['@odata.context']))

uriHost returns the portion of the URL between https:// and the first /.
Example: https://www.google.com/ → www.google.com

646311909-WordTemplateFlow-Step-3

Retrieve your template's entity code

641482956-WordTemplateFlow-Step-3

Add another compose action to capture the information that will be sent to generate the populated word template.
Use the following structure, replacing the appropriate selections. Do not add or remove any additional punctuation.

{
 "EntityTypeCode": REPLACE_WITH_ENTITY_CODE_NUMBER,
 "SelectedTemplate": {
   "@@odata.type": "Microsoft.Dynamics.CRM.documenttemplate",
   "documenttemplateid": "REPLACE_WITH_TEMPLATE_GUID"
 },
 "SelectedRecords": "[\"{REPLACE_WITH_ITEM_GUID}\"]"
}

1590049346-WordTemplateFlow-Step-4

Add an HTTP action (Premium connector) with the following settings:

1630635425-WordTemplateFlow-Step-8

Add a Parse JSON action for the Body of the HTTP call. Use the following schema:

{
  "type": "object",
  "properties": {
    "@@odata.context": { "type": "string" },
    "WordFile": { "type": "string" }
  }
}

440409413-WordTemplateFlow-Step-9

Create a new Notes table row to upload the file with the following required information:

Scroll through the list of Regarding columns, looking for the one that applies to the table your template is based off of.

Add a reference to the item so it will show up in that items' timeline control.

1367307034-WordTemplateFlow-Step-10

When successful you should see an entry in the timeline control with the attachment and any additional content you provided when creating the new row.

4227881538-WordTemplateFlow-Step-12

Excel Templates

Excel templates operate off a list of Dataverse items. The steps below show using a Excel template to generate an attendance report, but can be leveraged many different ways.

Start by creating a view or going to an existing view that contains the items you want in the report in the model-driven app.
Select Edit filters.

3731149424-ExcelTemplate---Step-1

Select the Download FetchXML button which will download an XML file to your browser's download location.

2339090056-ExcelTemplate---Step-2

This flow is going to be triggered by an item being added to a reports table, this is only one example of how you could do this.

4190809782-ExcelTemplate---Step-3

Add a compose action and paste the content of the Fetch XML file downloaded prior.

895701573-ExcelTemplate---Step-4

Create an action to get the items in the report. This is necessary to be able to get the environment URL dynamically rather than hard coding it into a flow.
Because we have the Fetch Xml query, we're going to populate that into action, rather than directly adding filter statements.

1681957403-ExcelTemplate---Step-5

Add a compose action to capture the current environment's URL using the following expression:

concat('https://', uriHost(body('List_rows_-_Sign_ups_for_report')?['@odata.context']))

uriHost returns the portion of the URL between https:// and the first /.
Example: https://www.google.com/ → www.google.com

3514464107-ExcelTemplate---Step-6

Add another compose action to capture the information that will be sent to generate the populated Excel template.
Use the following structure, replacing the appropriate selections. Do not add or remove any additional punctuation.

{
 "Template": {
   "@odata.type": "Microsoft.Dynamics.CRM.documenttemplate",
   "documenttemplateid": "REPLACE-WITH-TEMPLATE-GUID"
 },
 "FetchXml": "REPLACE-WITH-FETCHXML-REFERENCE",
 "QueryApi": "",
 "QueryParameters": {
   "Arguments": {
     "Count": 0,
     "IsReadOnly": true,
     "Keys": [],
     "Values": []
    }
  }
}

IMPORTANT: You must wrap the Fetch XML outputs in a string() expression for it to be properly formatted

1949014862-ExcelTemplate---Step-7

Add an HTTP action (Premium connector) with the following settings:

2113258081-ExcelTemplate---Step-11

Add a Parse JSON action for the Body of the HTTP call. Use the following schema:

{
   "type": "object",
   "properties": {
       "@@odata.context": {
           "type": "string"
       },
       "ExcelFile": {
           "type": "string"
       }
   }
}

3256878502-ExcelTemplate---Step-12

Create a new Notes table row to upload the file with the following required information:

Scroll through the list of Regarding columns, looking for the one that applies to the table your template is based off of.

Add a reference to the item so it will show up in that items' timeline control.

968508597-ExcelTemplate---Step-13

When successful you should see an entry in the timeline control with the attachment and any additional content you provided when creating the new row.

460744290-ExcelTemplate---Step-16

#Dataverse #Excel #Power Automate #Word #document templates