In this article, we will walk through the process of creating a document package in Power Automate using an XML-based definition of the individual elements within the package.
We will be creating an example document package consisting of a document for each account in our system. The example package will consist of the following elements:
- A document that is generated based on a DocumentsCorePack template
- A file that is retrieved from SharePoint
- A file that is retrieved from a note in Dynamics 365
We will demonstrate how to include these elements and the XML behind them.
1. Generating a document from a template
First, we must create a Flow in Power Automate. This can be an Automatic or Instant Flow, started by a trigger of your choosing.
Upon creating a Flow, we would need to begin by creating and initializing a variable. This variable will hold our custom XML. We will append additional XML to this variable throughout the example.
With the variable created, we can proceed to append our XML to it. To begin with, we will append the XML below. The converttopdf property has been set to true, but this can be set to false if the document needs to be created as a docx. If you use Sharepoint Integration to save your files, the savetosharepoint property can be set to true.
The XML is as follows:
<doc><docparts converttopdf="true" savetosharepoint="true">
Next, we add our template. The template, like our other elements, will be static. This means we can just include the template’s GUID and entity in the XML. This GUID comes from the MSCRM-ADDONS.com Template record inside our system.
To get the account ID for all accounts, we use the Dataverse – List rows function. The Apply to each function is then used to append the XML shown in Value to the variable for each account record.
2. Adding a Sharepoint document
Our Sharepoint document comes next. You can include this by adding the Sharepoint URL to the docpart. To get the Sharepoint URL, you must retrieve it from Sharepoint itself.
3. Adding a Note
Similar to the template above, the note is static as well, so we include its ID in the XML as well.
Finally, we close out our XML variable by adding the needed ending tags.
To create the document, we would need one more step. By adding the Create Multipart document (sync) step and including our variable, this allows for the document to be created upon executing the Flow.
In case the created document should be saved to an alternate path, another step would need to be added. Here, using Sharepoint as an example, you can set the URL, folder path, the file name and content. Since the created document was the output of the previous step, the file name and content can be retrieved, giving direct access to the generated document package.
Below is the XML used in the Flow with placeholders inserted. Please feel free to repurpose it for your own Flows!
<docparts converttopdf="true" savetosharepoint="true">
<docpart template="TEMPLATE" entity="ENTITY" entityid="ENTITYID"></docpart>
<docpart Note="NOTE" updatefields="true"></docpart>
That’s it! We appreciate your feedback! Please share your thoughts by sending an email to firstname.lastname@example.org.