Nintex Workflow for Office 365 – Copy Attachments to Document Library

Copying attachments from a List Item to a Document Library in Office 365 is not straightforward, until you actually get it working.  Then it totally makes sense.

I went through a bunch of blog posts and suggestions from people, and eventually, came across REST calls that people are making.  Now I’m not a guru with REST calls, so a lot of this is scavenged from places.  But it works and I LOVE IT!!

Let’s break this up into the individual bits.

Get Attachment URLs

This Call HTTP Web Service is performing a GET here and making the following call : ‎‏{Workflow Context:Current site URL}‌_api/web/lists/GetByTitle(‘‎‏{Workflow Context:List Name}‌’)/Items(‎‏{Current Item:ID}‌)/AttachmentFiles

That’s a fairly generic call, and I don’t believe you need to make any changes here.  We are getting the current list, then the current item and finally, the AttachmentFiles.  This will result in a Dictionary.

Loop through each Attachment

There are a few actions that I’m not going to go into here, which is Count the number of attachments in the response, create an index(counter) and Loop through each attachment.

Then we parse the data in that dictionary.

This gets the Server Relative URL from the response for the file we are working on.

This action gets the Filename of the attachment we are working on.

Copy the Attachment to a Document Library

The final part is the a REST call (POST) to copy the attachment to the destination library.

This is what the URL looks like : ‎‏{Workflow Context:Current site URL}‌/_api/web/getfilebyserverrelativeurl(‘‎‏{Variable:AttachmentURL}‌’)/copyto(strnewurl=’/Evangelism/My%20Pictures/‎‏{Variable:AttachmentFileName}‌’,boverwrite=true)

Notice that this URL you will need to modify, because in the 2nd half of it, I’ve had to hard code the /site/doclib  (/Evangelism/My%20Pictures).  You’ll need to tweak this to point to your destination library.  Also notice the last parameter, which is boverwrite and I have it set to true.  This means if a file with that name exists, it will overwrite it.

Downloads

Nintex Workflow for Office 365

Download the Move Attachments to DocLib Workflow

Leave a Reply

Your email address will not be published. Required fields are marked *