Cloud and Desktop flows a combination to manage PDF documents (Part 1)
Last year I had a project in Power Pages (Power Apps Portal still at that time) and the goal of this Portal was to allow contacts to register for events.
After each event the contact was entitled to claim a certificate as proof of attendance at that event. Therefore, the portal had a web page where the contact could choose to either generate the certificate for a specific event or generate a certificate that included all events the he/she had attended in the current year.
The certificate had to be generated as a PDF file, but there were three interesting parts in this requirement.
The first interesting part was that not only the event information had to be taken, but also the related sessions that the contact had attended. The second interesting part was that regardless of which option the contact chose in the Portal (generate the file for a specific event or for all events attended in the current year), only one PDF file had to be generated.
And the third interesting part was that the pdf file must contain a digital certificate as proof of authenticity.
The requirement was like this:
“As an event manager, I want to allow contacts to generate a PDF file as proof of attendance at one or more events in the current year. Regardless of the option they choose, only one PDF file with a digital certificate must be generated.”.
The first idea that came to my mind was that maybe the Dataverse word templates could help me, but there is a limitation here and it is about the child records, the Dataverse word templates use a relationship to show all related records and they cannot be filtered, and in my case I needed to filter and show only the sessions that the contact attended. So I discarded that option.
I know there are some third party connectors out there to generate PDF files and even to add a digital certificate to it. But then I remember that I can generate PDF files from a cloud flow using the Word Online connector.
Using that option will generate a PDF file for each event, but what about the part that is required to generate just one PDF file showing all attended events for the contact?. Well that’s when I remember that Power Automate Desktop has an option to merge PDF files into one.
Great, so the solution is to use a cloud flow to generate all the PDF files using Word Online connector and then use a desktop flow to merge them and finally add the digital certificate to that single PDF file.
That said, let me walk you through this first episode of a mini-series of blogposts to show you how PDF documents can be managed using cloud and desktop flows.
The first step is to understand the data model, in my case I have Event as a primary table and sessions as a child table.
There is also a many to many relationship between contact (attendees) and session:
The second step is to create a word document, be aware you have to enable Developer tab in Word ribbon, do click in the following order:
In the properties window give a name to the variable:
Do the same for start and end date:
Now the next step for this template is to add a table to show the attended sessions of the contact, create a table with two rows, the first row is the header of the table and in the second row add one variable per column:
In the previous image I added one variable (session name) for the Name column and another variable (sessionslot) for the Slot column.
Next you have to select the entire second row and click in Repeating Section Content Control:
And you have to give it a name to that variable as well:
And we also have to add a final text at the end of the template, to show the contact’s name and the event’s name, and to do that just repeat the previous steps:
And that’s it for the word template, now you have to upload it to SharePoint or any other repository that can be accessed from Power Automate. In my case I putted it in SharePoint:
For this step we have two cloud flows, The first cloud flow will be called with an HTTP request from the Portal and the second cloud flow will be called with an http request as well but from the first cloud flow. Therefore we are going to have a structure of Parent child cloud flows.
You can do it all in a single cloud flow, however, if your cloud flow is being called from an external source (HTTP request), then it is better to keep it short and simple and delegate all the complex or heavy logic to a second cloud flow.
It’s also worth mentioning that you can use the “call a child flow” action to call a second flow from the main cloud flow, but note that you have the two minute timeout limitation with this action, so that’s why I’m going to use a webhook http request action, so I can bypass this limitation.
Let’s going to create the child flow first because that will contain all the heavy work.
The trigger must be When a HTTP request is received: