In this article, learn how to create a document package in Power Automate consisting of multiple elements. The definition of the documents to be included in the package is XML based. In this example, we will create a package consisting of a document for every account in our system.
First, we have to create a Flow in Power Automate. This can be an Automatic or Manual Flow, started by a trigger.
Next, we need to create and initialize a variable to build a custom XML for DocumentsCorePack.
Set the converttopdf value to True to create a single pdf file. False will create a docx instead.
If you use the SharePoint Integration to save your files, don´t forget to set the option Save to SharePoint to True.
Figure 1: Flow started by trigger
Next, we use the Dataverse – List rows function to get the account ID for all Accounts.
Figure 2: Dataverse – List rows function
The loop is then used to build the XML for all Accounts. The XML must look like the following:
</doc>
<docparts converttopdf="False" savetosharepoint="False">
<docpart template="ab36bcda-63a4-4513-a7c5-759a63fad1b2"
= Template GUID
entity="account" entityid="5e88db20-d2fc-480b-b656-a76a714af862" />
Entity ID here is the GUID from the Account, the template shall be created for.
This section needs to be repeated for all Documents to create
</docparts>
</doc>
Figure 3: XML for all Accounts
The blue lines that will show are the header and footer for the XML we need to create, and the black line is the dynamic part (required for each document to create).
The template ID and Entity are static in this example.
The Entry ID Account has to be built as a function: Items (‘apply to each’)[accountid].
Please note: The red section that will show is not part of the XML, but is part of the comments.
Figure 4: Entryid Account has to build as a function
In the last step, we append the end of the XML tab and execute the Automergeworking item that creates the document.
If you want to save the created document to a custom path, then do not use the CRM SharePoint integration. Instead, you have to add another step to your Flow.
Figure 5: Save created doc to a custom path
The file content must be build as a function (to convert it from base64).
That’s it! We appreciate your feedback! Please share your thoughts by sending an email to support@mscrm-addons.com.