cancel
Showing results for 
Search instead for 
Did you mean: 

Using Microsoft Flow Arrays

In this post, we will discuss another approach for merging multiple documents into a single PDF using Microsoft Flow. In previous blog posts, we had a look at the Iterative approach and REST API approach to merge documents to PDF.

Both approaches have their own advantages and disadvantages:

  • For the iterative approach we merge one document at a time, as this results in multiple merge requests, the number of operations, and time taken, increases.
  • To overcome the limitation of the iterative approach we used the REST API approach, which combines all operations into a single request, and is not subject to Flow’s 100MB size limitation. However, this only works when the input and output files reside in SharePoint Online.

To overcome the above limitations Muhimbi has come up with an awesome new approach for merging documents to PDF using the recently introduced Microsoft Flow Array technique.

 

Before we begin. please make sure the following prerequisites are in place:

  • An Office 365 subscription with Flow and OneDrive for Business support.
  • Muhimbi PDF Converter Services Online full, free or trial subscription (Sign up).
  • Appropriate privileges to create Flows.
  • Working knowledge of Microsoft Flow.

Now that we have all the prerequisite in place let’s start building our Microsoft Flow.

 

In this blog post we will push all the files from a OneDrive for business folder into an array and then pass it to the Muhimbi Merge action, all in one go. Once all the files are merged, we will store the resulting file in a separate folder. Feel free to update the Flow and read the files from a different provider such as DropBox, SharePoint, Google Drive, etc.

 

So without wasting any more time let’s start building our Flow. From a high-level our Flow looks as follows:

 

Step 1: For this demo we will use the “When a file is created” OneDrive for Business Trigger. Naturally you can use other triggers as well, whatever is applicable to your scenario.

In the action, specify the path to the Folder to monitor for new files.

 

 

Step 2: Add the OneDrive for Business “List Files in folder” Action and specify the folder containing the files to merge.

 

 

Step 3: Initialise a variable of type Array and Name it ‘Files’.

 

 

Step 4: Add the ‘Apply to each’ loop and set it to the “value” field, output of the OneDrive for Business “List Files in folder” action.

 

 

Step 5: Add the “Get file content” action and pass the ‘Id’ value into the File field (Id of OneDrive for Business “List Files in folder” Action action) and set the “Infer Content Type” to ‘No’.

 

 

Step 6: Add the “Append to variable” action and specify the following values:

  • Name: Files
  • Value:
{
  "source_file_name": @{items('Apply_to_each')?['DisplayName']},
  "source_file_content": @{body('Get_file_content')['$content']}
}

 

Step 7: Outside the “Apply to each” loop add the Merge Action, click “Switch to detail inputs for array item” and pass the “Files” variable (the output of the ‘Append to array variable’ action).

 

 

Step 8: Add the OneDrive for Business “Create file“ Flow action and configure it with reference to screenshot below.

  • “Folder Path”: In this demo just hard code it to a path of your choice. Please make sure you don’t use the same path as the input file, or you will create an infinite loop.
  • “File Name”: For this demo lets just hard code it to “Merged.pdf”
  • “File Content”: Processed file content (output of Step 7).

 

That is all there is to it, save your flow and upload a file to the source folder. After a few seconds the merged file will / should show up in the specified output folder.

 

Subscribe to my blog for the latest updates about SharePoint Online, Microsoft Flow, Power Apps and document conversion and manipulation.

Meet Our Blog Authors
  • Working daily with Microsoft Cloud to deliver the needs of my company, my customers and various Microsoft communities and forums. | Office 365 | Flow | PowerShell | PowerApps | SharePoint |
  • Co-founder of https://plumsail.com, Office 365 and SharePoint expert. Passionate about design and development of easy to use, convenient and flexible products.
  • Microsoft Business Apps MVP. Owner of ThriveFast, an Office 365 consulting company.
  • 7x Microsoft Business Solutions MVP (CRM)
  • I'm keen in MS technologies, SharePoint, Office 365 and development for them
  • Daniel is a Business Productivity Consultant & Microsoft Business Solutions MVP who is very enthusiastic about all things Office 365, Microsoft Flow, PowerApps, Azure & SharePoint (Online). Since the preview, Daniel has been working with Microsoft Flow and later on with Microsoft PowerApps. That led to him being awarded an MVP Award for Business Solutions. He loves to blog, present and evangelize about improving productivity in the modern workspace with these amazing tools!
  • Michelle is an Office 365 solution architect in Twin Cities, MN. She has been delivering business collaboration solutions for years with her focus on SharePoint and Office 365. Michelle is a recent board member of the Minnesota Office 365 User Group and has been a member of the SharePoint community since 2009. She is a frequent speaker at MNSPUG and SharePoint Saturday and co-chaired the Legal SharePoint User Group for 4 years. Her most frequent projects have involved rolling out a large deployment of Office 365, SharePoint Online intranet, build of a "CHAMPS" Office 365 user adoption program and most recently, SharePoint On-Premise to Online Migration. Michelle is very excited about cloud technology as it is shifting her IT Pro focus to collaboration strategy and technical adoption.
  • I'm a Microsoft Office Servers and Services MVP with a special interest in SharePoint, Office 365, Microsoft Flow, Microsoft Teams and PowerApps. I work at Triad Group Plc ( https://triad.co.uk)
  • Passionate #Programmer #SharePoint #SPFx #Office365 #MSFlow | C-sharpCorner MVP | SharePoint StackOverflow, Github, PnP contributor