Skip to content

Move SharePoint List Item Attachments with Nintex for Office 365

Working with attachments is a common need among our clients. In this article, I will show you how to work with attachments in Nintex for Office 365.

Work with Attachments in Nintex for Office 365

Working with attachments is a common need among our clients. If you need to do this in Nintex on an on-premises version of SharePoint 2013 or 2016, I’ve already posted a similar article here. In this article, I will show you how to work with attachments in Nintex for Office 365.


Workflow Variables

RequestHeaders Dictionary
ResponseContent Dictionary
ResponseHeaders Dictionary
ResponseStatusCode Text
ResultsDictionary Dictionary
ResultsCount Integer
LoopIndex Number
CurrentAttachmentURL Text
CurrentAttachmentFileName Text
CurrentMoveToURL Text
ResultsCollection Collection
DestinationDocumentLibraryPath Text


Setting the Document Library Path

First set a variable for the destination document library path. The document library path should be URL encoded, e.g. use %20 instead of space characters, and should use the internal name of folders found in the URL of the library, e.g. Shared%20Documents instead of Documents for the default SharePoint document library.



Using the HTTP Web Service

Next you will need to get a list of attachments using a SharePoint web service request. To start, use the Build Dictionary action to configure two values. The first should be “content-type” for the key and “application/json;odata=verbose” for the value. The second should be “accept” for the key and “application/json;odata=verbose” again for the value.


Then use the Call HTTP Web Service action to get a response that includes the attachment URLs and filenames. The Address for the action needs to be as follows:

{Workflow Context:Current site URL}‌_api/web/lists/GetByTitle('‎‏{Workflow Context:List Name}‌')/Items(‎‏{Current Item:ID}‌)/AttachmentFiles

The Request Type is HTTP Get and the Request Headers should go to a text variable along with variables for the Response Content, Response Header, ad Response Status Code. You will need to insert references to the Current site URL, List Name, and current item ID. Be sure to include the single quotes around the List Name token.



Understanding the response

Use a Get an Item from a Dictionary action to get the collection of attachment dictionaries from the response. The “Item name or path” configuration will need to be set to:


Use the Count Items in Collection action to count the number of items in the collection from the response.


You will then need to set a number variable to 0 and use the Loop N Times action to loop through the collection for each attachment.


Within the loop you will need to get the URL and filename for each attachment. Each item in the looped collection is a dictionary with attachment values, so first in the loop you will need to use a Get Item from Dictionary action to get each item by the loop index variable and place it into a dictionary variable.


Two Get an Item from a Dictionary actions need to be used to get the ServerRelativeUrl (this is the attachment URL) and the FileName (ServerRelativeUrl and FileName are the “Item name or path” settings needed to get these values).



Moving the Attachment to the Document Library

Next, you will need to build a URL to use to call a web service that moves the attachment to the document library. Again, you will need to insert references to various workflow context properties and workflow variables as shown.



First use a Build String action to construct the URL as follows:

‎‏{Workflow Context:Current site URL}‌_api/web/getfilebyserverrelativeurl('‎‏{Variable:CurrentAttachmentURL}‌')/moveto(newurl='‎‏{Variable:DestinationDocumentLibraryPath}‌/‎‏{Variable:CurrentAttachmentFileName}‌',flags=1)


Next use a Call HTTP Web Service to call the SharePoint API for moving the attachment. The Request Type will need to be changed to HTTP Post, and the Request Headers, Response Content, Response Headers, and Response Status Code drop down lists should also be set to the appropriate variables.


Finally, you might want to use a Log to History List action to log the progress and you will need to increment the loop index by 1 with a Do Calculation action.


Leave a Comment