Using Environment Variables to configure Word Template action in the cloud flows

By | July 5, 2021

Power Automate word templates are much more fun to work with than the classic D365 word templates, yet we can happily use them in the model-driven app with a bit of javascript:

https://www.itaintboring.com/dynamics-crm/power-automate-word-templates-in-model-driven-apps-forms-integration/

However, how are we supposed to deploy flows containing “Populate a Microsoft Word Template” action in different environments so that each environment had its own version of the template? Assuming this is how we would ensure proper ALM for the template files (wow that sounds crazy, but… we would not want developers to just update production version of the templates, right?)

To start with, let’s look at how that action would, normally, be configured:

image

Although, those user-friendly names are not, really, what the connector is using behind the scene. We need to look a bit deeper by using “peek code” option:

image

There are a few “id” strings there, and that’s what the connector is using instead of the friendly names it’s showing us.

Therefore, if we wanted to configure the action to take in dynamics values for those parameters, we would need to know those values. One way to get them for each environment would be to simply point that action to another environment, use “peek code”, copy the values, then do it for another environment, and so on.

Let’s assume we have correct values for each environment.

The next step would be to create 3 environment variables, configure default values, and use them to configure action parameters:

image

It’s worth noting that, unlike flow variables, environment variables will actually have values in the “design time”, which means the Flow will be able to parse the template. If you tried using flow variables, they would not be “set” yet, since it would only happen at run time. Hence, the action above would not be able to find the template in the design time, and you’d be getting an errors.

By I digressed. We are using environment variables above.

Now, all you need from here is:

  • Export your managed solution that includes the flow and required environment variables
  • In the target environment, open Default Solution, locate those 3 variables, and configure custom values which would be specific to each environment
  • You may need to turn the flow on and off, since cloud flows tend to cache environment variable values

For example, here is how one of those env variables is configured:

And voila… Every environment will now be loading document template from the proper location, yet those templates can even have minor differences as you can see on the screenshot below:

image

And that’s it.

PS. Btw, can’t help but mention implementing this kind of “ALM” might be a pain in the neck with the classic word templates since they are not solution aware at all, and the only way to copy them from one environment to another would be to manually update template files to match proper entity id-s… or to use XrmToolBox for that, since, I believe, there is a plugin there.

Leave a Reply

Your email address will not be published.