I’ve never been a big fan of Word Template in Dynamics 365 since they have quite a few limitations, and, yet, I had to use them every now and then since they are so easy to develop (till you run into the limitations, of course).
Besides, they are not so easy to deploy into different environments, so you’d almost inevitably need XrmToolBox (if you are ok with manual deployment) or a script like this one (if you wanted to automate the process)
But for the last few months I’ve been using Power Automate version of the Word Template, and I’m finding it much more useful:
https://docs.microsoft.com/en-us/connectors/wordonlinebusiness/#populate-a-microsoft-word-template
To create a template, we need to do a few things:
1. Create a new word document
2. Add controls to the document
This is where you need to open “Developer” tab and start adding controls. Just keep in mind that every control you put there should have a title, and that title is exactly what you’ll see in the Power Automate flow when setting up Word Template action:
2.1. What if I wanted to add a repeater above to display invoice fees?
I’d start by adding a plain text content control to the table row:
And I’d give it a title:
Would, then, select the whole row:
And would add a repeater:
As with any other content control, I’d add a title to the repeater:
As a result, once I’m back in the Flow designer, I can see Fee repeater there (may need to reload the Flow in the browser):
With the individual controls, it’s pretty straightforward – just use output from the other actions (or use expressions) to populate those.
It’s a little more tricky with the repeater, but it’s actually not that complicated.
What you need is an array variable, and you’ll need to add elements to that array which are all objects, and each of those objects should have properties which correspond to the titles of the controls used within the repeater.
If you lost me here, here is an example:
You might do it in the “apply to each” for a CDS (oh… sorry… Dataverse) entity (crap… table), or you might do it somehow else. You might add conditional logic when populating the array (so that’s less one limitation of D365 word templates). Basically, you have the power of Power Automate at your disposal when preparing values for the controls (repeating or not).
3. Finally, you need to configure “Word Template” actions and set template control values
For the sake of simplicity, I’ll use static values for the individual controls.
I will, however, switch to the “array” mode for the repeater:
And, for the repeater, I will use my “Fees” variable:
Time for a test? Let’s just add an action to send the result to me by email:
And, once I run the Flow(it’s an HTTP Request flow. I just run it by opening that URL in the browser… have to be configured to allow “Get” method on the trigger) and the email comes in here is what I see:
How about sorting? Well, just sort that array.
How about filtering? Same thing – just don’t add those values to the array.
And how about using this directly from the model-driven app?
That’s in the next post.
I’ve been using it a lot the last few days.
The first trick is to forget about the old templates and enter your own codes!
Hi Alex, the setup above is to have 1 Flow per template. I am trying to figure out how 1 generic flow can deal with multiple Word templates, each based on one or more of a fixed set of say 5 entities. The aim is to have end users design their own Word templates using a dictionary of fieldnames, without having to create a new Flow for it (too technical). Would you think this is possible?
Hi Alex,
I intend to build a modular template (i.e. create a word file from scratch and include different sections depending on flow input/Dynamics products etc) using Power Automate.
Each of these sections could have specific formatting, image included, Dynamics content. Have you ever tried anything like this?
Thanks,