In this blog you can learn how to create a Mulitpart XML document with Power Automate. This example is using the account Entity and creates a document for all “Accounts“.
First we have to create a Flow in Power Automate. This can be an Automatic or Manual Flow, started by a trigger like here.
Figure 1: Flow started by trigger
Then we are creating and initialize a variable to build a custom XML for DocumentsCorePack.
Set the “converttopdf” value to “True” to create one single pdf file. “False” will create a docx instead.
If you use the SharePoint Integration to save your files, don´t forget to turn the option “Save to SharePoint” to “true“.
And then we use the Dataverse – List rows function to get the account ID for all Accounts.
Figure 2: Dataverse – List rows function
Then the loop is used to build the XML for all Accounts. The XML has to look that way:
</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 are the header and footer from the xml we need to create, the black line is the dynamic part (required for each document to create).
The template ID and Entity is static in this example.
The Entryid Account has to build as a function: Items (‘apply to each’)[accountid].
Please note: The red section is not part of the XML, just 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. Therefore 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 function (to convert it from base64 before).
That’s it! We appreciate your feedback! Please share your thoughts by sending an email to support@mscrm-addons.com.