Automate document creation with PowerApps, Power Automate and Encodian Flowr

December 4th 2023
Back to all blogs

This solution automatically creates and populates a Word document using PowerApps and Power Automate with Flowr actions. It will then also create a PDF rendition. For demo purposes, we are using personas to present a real-life scenario. This solution was presented at the South Coast Summit in October 2023 by Sophie Charlwood and Ben Haynes. So if you’re looking to automate document creation with PowerApps and Power Automate, you’ve found the right blog!

The blog has been broken down into these smaller sections:

Scenario

This scenario is a health and safety PowerApp which delivers an incident form completed should an injury occur. This is just an example scenario for the solution; many similar use cases can benefit from this type of solution. The persons involved are the injured ‘Builder’, the ‘Site Injury Advisor’ and the ‘Site Manager’:

After the ‘Builder’ has contacted the ‘Site Injury Advisor’ about their new incident, the ‘Site Injury Advisor’ needs to select the relevant form and complete the details considering the information provided by the ‘Builder’.

The ‘Builders’ doctor’s information has been previously saved in Dataverse. That means it is automatically surfaced in the form, but these details won’t be editable in this scenario.

When the complete button is pressed, a ‘Document Creation’ Power Automate flow is initiated. This creates a PDF rendition of the completed form by using our Populate Word Document and Convert Word actions. It then asks for approval from the ‘Builder’ to confirm the details recorded by the ‘Site Injury Advisor’ are correct.

When the ‘Site Manager’ accesses the app, they are presented with a gallery containing all the reported incidents.

The following logic has been applied to allow a ‘Site Manager’ to sign off an incident:

Incident Signed Off – Not Signed Off Icon – Visible Property

If(ThisItem.'Incident Signed?' = true,false,true)

Incident Signed Off – Not Signed Off Icon  – Visible Property

If(ThisItem.'Incident Signed?' = true,true,false)

In the Dataverse Incidents table, there is a column called ‘Incident Signed?’ which defaults to ‘No’. When an incident is ‘Signed off’, a Power Automate flow updates this value to ‘Yes’. This switches the icon in the Power App’s ‘Incident Signed Off’ column.

Document Icon – Visible Property

If(IncidentNotSignedIcon.Visible = true,false,true)

The document icon is only visible when an incident has been ‘Signed off’, and the summary document has been created. That means it is visible when the not signed off icon in the Incident Signed Off column is not visible.

The modal pop-ups are managed with containers and altering the visible property to either show or hide the container and, therefore, the pop-up. There is one pop-up container with two containers inside, one for incident information and one for incident sign-off. Each container has different elements, changing what is shown.

Information Icon – OnSelect Property

Select(Parent); // selects the gallery item
Set(VarOpenPopUp,true); // sets variable VarOpenPopUp to true which opens the pop up
Set(VarIncInfo,true); // sets variable VarIncInfo to true which sets the incident information container to visible

Incident Signed Off – Not Signed Off Icon – OnSelect Property

Select(Parent); // selects the gallery item
Set(VarOpenPopUp,true); // sets variable VarOpenPopUp to true which opens the pop up
Set(VarSignOff,true); // sets variable VarSignOff to true which sets the sign off container to visible

Encodian Flowr

Flowr’s Populate Word Document action uses JSON inputs. A JSON payload can be created from all the dynamic content available within the Power Automate flow. The JSON keys must match exactly the token names added to the word template so that the action knows where to place the data in the document. The action works with text, dates and images, meaning all the data we need to put in the template can be done with one action. Images in Dataverse are already stored in Base64 format. This means we need to add Base64 after the key name in the template tag.

This produces a new file where the tokens have been replaced with the dynamic data values provided. To finish the flow, the Word document is converted to PDF (using Flowr’s Convert Word action) and emailed back to the ‘Builder’ so that they can see the ‘Site Manager’ has identified mitigating actions to stop similar incidents occurring in future.

Result

The final PDF document will look like this:

We hope you have found this blog about how to automate document creation with PowerApps and Power Automate useful! But we always welcome feedback, so please reach out via our chat or email us at sales@encodian.com to chat!

Author
Sophie Charlwood

Technical Evangelist

Back to all blogs

You might also be interested in...