Document generation before your eyes and on demand with Power Automate

Scenario: you have a really cool model-driven power app that you use to track work and create invoice records, you call it ‘Micro Financial Enterprises’. But generating the invoice documents to send to clients at the end of the month is far too clunky.

Not anymore!

Document generation in model-driven Power Apps is nothing new but there are lots of ways to do it, each has its pros and cons.

  • Pros: it can be run on demand from the command bar as a document template or ‘Export to PDF’; relatively simple to set up without building or deploying anything; can be personal or system level; it does exactly what it says on the tin

  • Cons: major limitations in terms of what data you can access (the good old one hop rule applies); you cannot filter or sort lists; the document doesn’t get saved anywhere just downloaded to the users device locally and so many more

Pros: all the data, filters and sorting you can ever dream of; ability to manipulate and transform data from multiple data sources; it uses power automate which immediately makes it cooler; save the file wherever is most relevant to your needs

  • Cons: its a confusing user experience to click lots of buttons and nothing visually happens, (since Power Automate is working in the background), using a flow step means the users has to sit, wait and refresh until somehow the document is created somewhere and maybe shows up as a link on the record or a note in the timeline. If it fails, it fails silently and you have to go digging to soo what went wrong or even find out that it failed.

Option 3 Awesome: Use a model-driven app Custom Page with Power Automate document generation

  • Pros: all the pros from Option 2; customise the user experience exactly how you want; surface and connect data from anywhere; its part of your model-driven app; ability to handle errors gracefully and informatively; one click (or less) flow run experience.

  • Cons: you need to scrub up on your PowerFX skills (but future you will be grateful)

High level technical summary:

  • Word document is created and stored in OneDrive so any updates made to the document after generation are picked up in the PDF conversion

  • If you see a button, it calls a flow (using the Power Apps V2 trigger) and passes back useful variables

  • Dataverse tables used on this page are: Account, Invoice, Work Items, Email Message, Contacts, Users, Services and Invoice Periods

Take home message(s):

  • Using custom pages for document generation in model-driven apps is cool and terribly useful

  • It structures data properly in dataverse but visualises it enjoyably - without any code based magic, just Power automate and Power FX.

  • Go use custom pages to replace your clunky old document generation processes in Dynamics 365 and model-driven Power Apps and live happily ever after

PS. I have no idea how to write up about how I did this from end to end, but if there are specific things you would be interested in finding out more about please let me know!

Previous
Previous

Insert your email signature from Dataverse using Power Automate

Next
Next

Capture Referrer URL with Dynamics 365 Marketing Forms