This post should have been written before the one where I had a sample script which can call a flow to download a document, but, since these two posts happened to come out in the reverse order, it seems this is, technically, a prequel. Hm… If you have not seen the previous post, maybe read this one first:)
Anyways, there was a question about the actual flow, so I wanted to explain what’s happening in the flow. Here we go:
1. There is an HTTP trigger followed by a Compose action to extract record id from the query parameters
Why am I using “Get” method? Well, it’s just so I could test the flow directly from the browser address bar.
2. From there, I should have added a few Dataverse actions to query data for the Word Template, but I cheated. Instead, the data is “hardcoded”:
3. In the next action, the flow will initialize WordDoc “object” variable
Why do I need that? Basically, it’s because the flow can generate document in two different places. So, in both places, I’ll set the variable, and I’ll use it later in the single response action.
4. Just to make it more confusing, I have a condition in the flow where the Flow will either user Power BI Paginated Report or Word Template to produce word document
Here is the remaining piece of that scope action above:
Why is there such logic? It’s a demo flow, so the purpose is to demonstrate two ways of generating the document (through Power BI Paginated Reports and through Word Templates), and, then, to show that it does not change the end result.
Although, realistically, there are differences.
Power BI action will take at least 30 seconds to execute. Word Template action will work much faster. That said, Power BI Paginated Reports (which are, basically, SSRS… if you are more familiar with SSRS) can help you build pixel-perfect reports (unlike Word Templates, where precise formatting can be more complicated)
But that does not change anything for the client – whatever the flow decides to use for document generation, as long as it has that HTTP trigger, and as long as it sends Word document back to the client, the client does not care.
5. And here is how the response is sent back
6. The same flow would also send an email with file attachment
You might ask what’s that Compose action doing there – why not to use “WordDoc” variable directly? It’s because “Attachments Content” seems to expect something other than object, and, in those cases, I find that a variable might not be compatible with the action parameter type, but Compose would usually be (since it’s sort of “generic”). So, a variable is used for the Compose input. And, then, Compose output is used for the email action. Think of it as type conversion, even if a little weird one.
Hope this helps.