Nintex Workflow for Office 365 – Merge all documents in Document Set

In this post I will show how to iterate over multiple files in document set and Merge them together, all using Nintex Workflow for Office 365.

A popular topic which I have written about document Merging before for Microsoft FlowNintex Workflow On-Premise and SharePoint Designer workflow.

Before you begin, please make sure the following prerequisites are in place:

  • Muhimbi PDF Converter for SharePoint Online is installed and enabled in your workflow’s site with a free, full, or trial subscription.
  • A Muhimbi PDF Converter SERVICES Online subscription, linked to the SharePoint Online subscription.
  • Appropriate privileges to create Nintex Workflows.
  • Working knowledge of SharePoint Online, REST APIs and Nintex Workflow.

So without wasting any more time let’s start building our Nintex Merge Workflow for Office 365. From a high-level our Nintex Merge Workflow for Office 365 looks as follows:



Do not worry the Workflow looks long and complicated but TRUST ME! if you follow along you will form sure learn new things and you should be able to achieve your requirements or Just Download the Nintex Workflow Template file.

Note: I will Skip the “Log to History” action as they are used for Debugging.



Step 1:

  • Create the Variables with reference to details below.
NameTypeInitiation
ResponseHeadersDictionaryNo
ResponseContentDictionaryNo
TempDictionaryDictionaryNo
FileServerRelativeUrlTextNo
AttachmentFileNameTextNo
ResponseCodeTextNo
RequestHeadersDictionaryNo
ResponseCountIntegerNo
LoopCountIntegerNo
TempLoopCountNumberNo
MergeListTextNo
JSONTextNo
MuhimbiResponseTextNo
MuhimbiResponseCodeIntegerNo
API_KeyTextNo


Step 2:

  • Add the ‘Build Dictionary’ action.

  • Configure the ‘Build Dictionary’ action:
KeyTypeValue
Content-typeTextapplication/json;odata=verbose
AcceptTextapplication/json;odata=verbose
  • Click on the ‘Add’ Button’
  • Output – Select the ‘RequestHeaders’ variable.

Step 3:

  • Add the ‘Call HTTP Web Service’ action.
    • Address (URL of the remote server): {Workflow Context:Current site URL}‍/_api/web/GetFolderByServerRelativeUrl(‘<server_relative_url_of_document_set>’)/Files?$select=ServerRelativeUrl
    • Request Type(type of HTTP request) : Get        
    • Request Headers : Select the ‘RequestHeaders’ variable from dropdown.
    • Request Content : Leave it blank.
    • Response Content : Select the ‘ResponseContent’ variable from dropdown.
    • Response Headers : Select the ‘ResponseHeaders’ variable from dropdown.
    • Response Code : Select the ‘ResponseCode’ variable from dropdown.


Step 4:

  • Add the ‘Get item from Dictionary’ .


  • Dictionary: Select the ‘ResponseContent’ variable.
  • Item name or path: ‘d/results’
  • Output: Select the ‘TempDictionary’ variable.


Step 5:

  • Add the ‘Count Items In A Dictionary’ action.

  • Dictionary variable: Select the ‘TempDictionary’ variable
  • Output : Select the ‘ResponseCount’ variable.


Step 6:

  • Add the ‘Set Workflow Variable’ action.

  • Variable: Select the ‘LoopCount’ variable
  • Value: Equals (Value) : 0       


Step 7:

  • Add the ‘Loop N Times’ action.
  • Repeat Count: Equals ‘Workflow Variable’ to ‘ResponseCount’.


Step 8:

  • Inside the ‘Loop N Times’ action add the ‘Get An Item From A Dictionary’ action.
    • Dictionary: Select the ‘ResponseContent’ variable.
    • Item name or path:  d/results(‍{Variable:LoopCount}‍)/ServerRelativeUrl
    • Output: Select the ‘FileServerRelativeUrl’ variable.



Step 8:

  • Inside the ‘Loop N Times’ action add the ‘Do Calculation’ action.

  • First operand: Equals ‘Workflow Variable’ select variable ‘LoopCount’.
  • Operator: plus        
  • Second operand: Equals ‘Value’ ‘1’
  • Output: Select variable ‘TempLoopCount’



Step 9:

  • Add the ‘Set Workflow Variable’ action.

  • Variable: Select the ‘LoopCount’ variable
  • Value: Equals ‘Workflow Variable’ select variable ‘TempLoopCount’.

Step 10:

  • Add the ‘Build Merge String’ action.

  • String : ‍{Variable:FileServerRelativeUrl}‍;\r\n ‍{Variable:MergeList}‍
  • Output : MergeList


Step 11:

  • Add the ‘Set Workflow Variable’ action.

  • Variable: Select the ‘LoopCount’ variable.
  • Value: Set your Muhimbi API_KEY.


Step 12:

  • Add a ‘Build String’ action and set the Output to the JSON variable.

  • In the String field enter the following:
[
 "use_async_pattern":false,
	"sharepoint_file":
		[ 
		"site_url":"‍{Workflow Context:Current site URL}‍", 
		"source_file_url":"‍{Variable:MergeList}‍",
		"destination_file_url":"‍{Workflow Context:Current site URL}‍Shared%20Documents/sample.pdf"], 
		"document_start_page":"Starts on the default page", 
		"fail_on_error":true
		]
]


Note: You may be familiar with JSON notation, but please note that we have replaced the curly braces – { } – with square brackets [ ]. This is due to a bug in Nintex Workflow for Office 365. For more details see the “PAY ATTENTION TO” section in this article.


Step 13:

  • Add the “Replace Substring in String” action.

  • Search String : [
  • Replace String : {
  • String : Workflow Variable {Variable:JSON}‍
  • Output        Set the ‘JSON’ variable


Step 14 :

  • Add the ‘Replace Substring in String’ action.

  • Search String : ]
  • Replace String : }
  • String : Workflow Variable {Variable:JSON}‍
  • Output : Set the ‘JSON’ variable.

Step 15:  

  • Add the “Web Request” action and configure it as follows:

  • URL: https://api.muhimbi.com/api/v1/operations/merge_to_pdf
  • Method: POST
  • Content type: application/json
  • Add header: Click Add header, specify API_KEY as the Header name and insert a reference to the API_KEY workflow variable for the Header value.
  • Body: Select the Content option, add a reference to the JSON workflow variable in the Data field.
  • Store response content in: MuhimbiResponse.
  • Store http status code in: Status.

Click the Save button.

Step 16:

  • In the Nintex Workflow ribbon, click Save and then click Publish and Submit.

Step 17: 

  • Select the Document Set.
  • Access the Workflows page for the list item: Click More options (…), click Advanced, and then click Workflows.


  • After few seconds, and you should get a Merged file in the ‘Shard Document’ Library.


Subscribe to this blog for the latest updates about SharePoint Online, Power Automate (Microsoft Flow), Power Apps and document conversion and manipulation using The PDF Converter.

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 )

Facebook photo

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

Connecting to %s