Merging documents using SharePoint Designer workflows

Over the past few months I have been working a lot with Microsoft Flow, Nintex and other Workflow Platforms. It’s been a while since I wrote about SharePoint’s own workflow platform SharePoint Designer.

In this post I will show how to iterate over multiple files and merge them together, all using SharePoint Designer. A popular topic which I have written about before for both Microsoft Flow and Nintex Workflow.

Please note that in this post I am using the SharePoint 2013 workflow engine, also known as the Workflow Manager, which is still present in the latest SharePoint on-premise and Online versions. This example does not work in the legacy SharePoint 2010 workflow engine.


Before we begin, I would like to shed some light on Workflow Manager in SharePoint Server.

NOTE: If you are using SharePoint Online, you can skip this section and continue from section “Prerequisites for SharePoint Online”

Workflow Manager in SharePoint Server brings major advancements to workflows. It uses a new workflow service that introduces features such as REST based web service calls without writing custom code (Something we’ll use in this example).

Starting with SharePoint 2007, a workflow engine is installed automatically whenever SharePoint is deployed. This is known as the legacy workflow engine, a.k.a the SharePoint 2010 workflow engine.

The optional Workflow Manager, introduced in SharePoint 2013, requires a separate installation. For a detailed guide see How to: Set up and configure SharePoint 2013 workflows.

When you create a workflow in SharePoint Designer 2013, you must select the Platform Type, either “SharePoint 2010 Workflow” or “SharePoint 2013 Workflow”, the latter being the Workflow Manager used in this tutorial.

The same options are available when building workflows in SharePoint Online. Please keep in mind that in SharePoint Online it is not possible to invoke 3rd party workflow components in the 2010 workflow, so always select the 2013 workflow option.


Prerequisites for SharePoint On-Premise Servers:


Prerequisites for SharePoint Online:


From a high level our workflow looks as follows:

Image too small? Click the image to open in full screen.

Let’s Start Building our workflow:

Step 1:  Create a List workflow using SharePoint Designer 2013. Associate it with the relevant Document Library.


Step 2: Enter “Muhimbi Merge Workflow” and Click Ok to provision the new workflow.


Step 3: Add Local Variables.

  • FileList (String) – This variable stores the list of file Urls that are going to be merged into the pdf.
  • ResponseContent (Dictionary) – This variable will store the response received from web service.
  • responseCode (String) – The response status (Ok/Failed) is returned from the web service call and stored in this variable.
  • RequestHeader (Dictionary) – This will be used as a header for web service calls.
  • ListofServerRelativeUrls (String) – This is used to temporarily store file urls and also used in the Loop.
  • CurrentServerRelativeUrls (String) – This is used to store the current url and also used in the Loop.
  • Index (Integer) – This is used to store the file count and used in the loop.

Note: Some (other) variables will be automatically created when you add the various SharePoint Designer actions.


Step 4: Add the “Set Workflow variable” to the SharePoint Designer Pane.

  • Set the Workflow variable “index” value to 0.

Step 5: Add the “Build Dictionary” action.

Click on the this and add the following Key/Value pairs.

  • Accept : application/json;odata=verbose
  • Content-Type : application/json;odata=verbose
  • Set the “Output to” variable to “RequestHeader”.


Step 6:  Add the “Call HTTP Web Service” action.

  • Once inserted select the line that contains the web service workflow action and click the ‘Properties’ button in the ribbon.

The Following window should open:

Configure the Parameters with reference to details below:

e.g. https://tenantname.sharepoint.com/sites/sitecollectionname/_api/web/GetFolderByServerRelativeUrl(‘Libraryname’)/Files?$select=ServerRelativeUrl

Note: As you can see in the Url above, I am only fetching the ServerRelativeUrl property because we need file urls. The Site-Url can also be made dynamic from the current workflow context.

  • RequestHeaders: Set the “RequestHeader” workflow variable.
  • ResponseContent: Set the “ResponseContent” workflow variable.
  • ResponseStatusCode: Set the “responseCode” workflow variable.


Step 7: Add a “Log to History List” action. Log “responseCode” to the history list so that we know the status of the response.


Step 8:  Add an “If any value equals value” condition and set it to If “responseCode equals OK”.

 It checks for the web service response code and proceed only if it is successful.


Step 9:  When the “If condition” evaluates to True.

  • Add the “Get an Item from the Dictionary” action. Click on the items by name or path link and type ‘d/results’, set the “from” variable to the “ResponseContent” workflow variable and Output it to the “FileList” workflow variable.
  • Add the “Count Items in Dictionary” action. Click on the dictionary link and set the variable to the “FileList” workflow variable and set the Output to variable “count”.
  • Add the “Log to History List” action. Log “Count” to the history list so that we know the total number of files we need to merge.


Step 10: Add the “Loop n times”  action.

Image too small? Click the image to open in full screen.

  • Set “The Contents of this loop will run” to “Variable: Count”.
  • Add the “Get an Item from the Dictionary” action. Click on the “items by name or path” link and type ‘d/results/([%Variable:index%])/ServerRelativeUrl‘, set the “from” variable to the “ResponseContent” workflow variable and Output it to the “Current ServerRelativeURL” workflow variable.
  • Add the “Set Workflow Variable” action and Set the workflow variable to “ListofServerRelativeUrls” and use the String Builder to set it to:

[%Variable:ListofServerRelativeUrls%]

[%Variable:Current ServerRelativeURL%]

  • Add the “Do Calculation value” action and set the value to the workflow variable “Index” plus “1” and set the Output to the “calc” variable.
  • Add the “Set Workflow Variable” action and Set the workflow variable to “index” and the value of the workflow variable to “calc”.


Step 11: Outside the Loop, Add “Log to History List” action.

  • Log the variable “ListofServerRelativeUrls” to the history list.


Step 12: Add the Muhimbi “Merge Documents to PDF” Action and set the “these documents” field to the workflow variable “ListofServerRelativeUrls” and “this field” to “Merged.Pdf”.

Image too small? Click the image to open in full screen.

Note: I am hardcoding the Filename, however you can Dynamically create the file and also specify a different destination.


Step 13: Set the “Transition to Stage”, Go to “End of Workflow”.


Step 14: Now it’s time to test our Workflow.

  • Upload a few documents to the Library.
  • Manually Start the Workflow on a document.
  • Check the workflow history list and make sure there are no errors.

Once the workflow has completed, the merged file should appear in the specified location.

Happy Converting……

One thought on “Merging documents using SharePoint Designer workflows

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s