• Release History
  • Documentation
  • Back to www.mscrm-addons.com
  • Release History
  • Documentation
  • Back to www.mscrm-addons.com
home/Knowledge Base/DocumentsCorePack(DCP)/Build a Multipart XML flow that concatenates documents into one file

Build a Multipart XML flow that concatenates documents into one file

2822 views 0 Updated on February 5, 2025

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.   

Example

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:

  1. A document that is generated based on a DocumentsCorePack template
  2. A file that is retrieved from SharePoint  
  3. 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. 

Define the variable that holds the XML definition of the package
Figure 1: Define the variable that holds the XML definition of the package

With the variable created, we can proceed to append our XML to it.  To begin with, we will append our initial <doc> and <docparts> tags, along with a few parameters.  The savetosharepoint parameter will save the generated document to SharePoint, while the stsentitytype and stsentityid parameters will define the SharePoint save location.  The converttopdf parameter, when set to true, will save the generated document as a PDF.

The XML is as follows: 

<doc><docparts savetosharepoint="true" stsentitytype="account" stsentityid="ENTITYID " converttopdf="true">
Appending the properties
Figure 2: Appending the properties

Next, we will need to get the IDs for all of our accounts (using the Dataverse -> List rows action) and create a variable that will contain the number of accounts in our environment.

Getting a list of accounts
Figure 3: Getting a list of accounts
Intializing a record count variable
Figure 4: Intializing a record count variable

We require both actions for our Apply to each loop, which is needed to append a docpart containing our template information for each account record.  Our loop will look like this:

Our loop structure.  Note the condition and record variable decrement step.
Figure 5: Our loop structure. Note the condition and record variable decrement step.

Each docpart will contain the template’s GUID, entity name, and entity GUID (retrieved from our List rows action) save for the last one, which will have an additional parameter added to it: the updatefield parameter.  This parameter needs to be added to the last docpart to properly update any included Word fields across all templates.  Thus, this last docpart is placed in the false condition that will be triggered when the last record in the list is reached.

The loop, now showing the XML to be added depending on the condition result
Figure 6: The loop, now showing the XML to be added depending on the condition result

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. 

The XML for our SharePoint docpart
Figure 7: The XML for our SharePoint docpart

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.  Since this is our last docpart, we can also add the closing <docparts> and <doc> tag to it.

The XML for our Note docpart
Figure 8: The XML for our Note docpart

Finishing up 

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. 

Generating our document by using our "VarXML" variable
Figure 9: Generating our document by using our “VarXML” variable

In case the created document should be saved to an additional, 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. 

Saving our generated document to another SharePoint location
Figure 10: Saving our generated document to another SharePoint location

Sample XML

Below is the XML used in the Flow with placeholders inserted.  Please feel free to repurpose it for your own Flows! 

<doc>
   <docparts savetosharepoint="true" stsentitytype="ENTITY" stsentityid="ENTITYID" converttopdf="true">
      <docpart template="TEMPLATE" entity="ENTITY" entityid="ENTITYID"/>
      ...
      <docpart template="TEMPLATE" entity="ENTITY" entityid="ENTITYID" updatefields="true"/>
      <docpart SharePointUrl="SHAREPOINTURL"/>
      <docpart Note="NOTEID"/>
   </docparts>
</doc>

That’s it! We appreciate your feedback! Please share your thoughts by sending an email to support@mscrm-addons.com.

Was this helpful?

Yes  No
Related Articles
  • How to migrate One-Click-Actions (OCAs) between environments
  • Document Generation via Copilot in Dynamics 365 Sales using DocumentsCorePack
  • DocumentsCorePack: Best practices for Dynamics 365 on-premises to online migration projects
  • Multilingual Support in DocumentsCorePack
  • Configure DocumentsCorePack within custom pages
  • Ensuring correct time zone display for DateTime fields
Leave A Comment Cancel reply

You must be logged in to post a comment.

Latest Articles
  • How to migrate One-Click-Actions (OCAs) between environments
  • Document Generation via Copilot in Dynamics 365 Sales using DocumentsCorePack
  • DocumentsCorePack: Best practices for Dynamics 365 on-premises to online migration projects
  • Multilingual Support in DocumentsCorePack
  • Recap: ColorCloud 2025
Popular Articles
  • DocumentsCorePack Template Designer – Getting Started
  • Step-by-Step: How to configure a One-Click-Action
  • Application Access for Dynamics 365
  • How to find your environment’s unique name in Microsoft Dynamics 365
  • How licenses are counted
Top Rated Articles
  • “Undefined”-labels in Chrome and Edge 114 and higher
  • Important information for Dynamics 365 online customers using DocumentsCorePack and/or AttachmentExtractor
  • How to activate the DocumentsCorePack Connector for PowerApps & Microsoft Flow
  • How licenses are counted
  • How to insert Condition Fields in DocumentsCorePack Templates designer
Categories
  • *News and General Infos* 62
  • Webinars 45
  • Template Designer(DCP 196
  • DocumentsCorePack(DCP 252
  • TelephoneIntegration (TI 65
  • AttachmentExtractor (AE 72
  • PowerSearch (PS 50
  • ActivityTools (AT 61
  • SmartBar (SB 54
  • GroupCalendar (GC 47
Our Vision

“We see it as our purpose to provide products that simplify and speed up our customers’ Microsoft Dynamics 365 experience.”

Knowledgebase
LogIn
mscrm-addons.com
  • Products
  • Online Shop
  • Downloads
  • My Account
About Us
  • About Us
  • Case Studies
  • Newsletter
  • Partner Program
  • Contact
Support
  • Support
  • Terms & Conditions
  • Documentation
  • Webinars
  • Legal Documents
  • Impressum
  • © 2022 www.mscrm-addons.com. All Rights Reserved.