Vadim Tabakman

Jump to bottom

Nintex Workflow - Delete All Attachments UDA

An interesting scenario came by my desk, where someone wanted to take attachments from the current item, move them to a document library in SharePoint, and then delete those attachments, so that there weren't duplicate files.  A great scenario that Nintex Workflow is perfect for.

This is scenario that I think many of you have come across, or may in the future.  The actual deletion of the attachments is something I found I could put into a User Defined Action, because it makes it that much easier to reuse in other workflows.  It also makes it very easy to share with everyone.

Design

As you can see, there isn't that much to this UDA.  SharePoint comes with the Lists.asmx web service.  Essentially, we are using two of the web methods it provide.  The GetAttachmentCollection and the DeleteAttachment.

The GetAttachmentCollection web method will return XML, which we can get data out of, using the Query XML action.  This pulls out each attachment URL and stores it in a Nintex Workflow collection variable.

Then, we iterate through each URL and we call the DeleteAttachment web method, to delete that off of the current item.

GetAttachmentCollection

In the screenshot above, you can see that I'm utilizing some common properties, like the Web URL, List Name and the item property ID.  This makes the UDA dynamic, so that it works on the item I'm currently running my workflow on.  If you want to extend this UDA, you could add some parameters to specify the List Name and the Item ID, and that way, it could be made to delete attachments from items anywhere in the site.

The result is stored in a Text variable, so that we can parse it.

Query XML

The Query XML action is using a very simple XPath expression, //defaultNS:Attachment, to pull out all the attachment URLs from the XML and store them in the collection variable.

For Each

Now that we have all the Attachment URLs in a collection variable, we can use the For Each action to iterate through each of the URLs.  One of the great features of the For Each, is that although it is a loop, it isn't affected by Safe Looping.  So there is no delay between each iteration of the For Each.

DeleteAttachment

 

The final action in the UDA, is the Call Web Service action that calls the DeleteAttachment web method. Again, we are using common properties like Web URL, ListName and the Item property ID.  We are also passing in the URL that we have within the For Each.

Possible Enhancements

As I mentioned above, this UDA is limited to the current item the workflow is running on.  But you could enhance this UDA with these options:

1. add parameters to handle List Name, Item ID and even a Site URL so that the UDA can delete attachments from any item in any site.

2. add error handling to the Call Web Service.  This is always a good preventative option so that if any issue occur, you can capture the error and do something with it.

3. add logic to the For Each action, so that only a subset of the attachments are removed.  eg. you may want to keep PDFs attached, and everything else removed.

Downloads

Nintex Workflow 2013 - choose one of the options below

Download the UDA (NWF)  - Download and import into the User Defined Action designer page

Download the UDA (UDA)  - Download and import into the Manage User Defined Actions page

Posted by Vadim Tabakman Tuesday, December 30, 2014 8:09:00 AM Categories: Attachments Call Web Service Collection Variable For Each Nintex Workflow Nintex Workflow 2013 Query XML User Defined Actions
Copyright Vadim Tabakman
Rate this Content 0 Votes

Comments

Thursday, June 25, 2015 9:28:02 AM

re: Nintex Workflow - Delete All Attachments UDA

Hi ,

While executing web service I am getting "The remote server returned an error: (500) Internal Server Error" .

User is farm admin .

 

Monday, August 3, 2015 12:44:50 PM

re: Nintex Workflow - Delete All Attachments UDA

Hi Amar,

500 error means the data you sending is probably not valid for the server request.

Try typing data in and see if that works, then add variables and properties.

cheers,

Vadim

Friday, August 28, 2015 12:55:02 PM
Ashish Kumar Singh
Gravatar

re: Nintex Workflow - Delete All Attachments UDA

Hi Vadim,

I have tried to implemented the same by extending the functionality by adding parameters list name and item ID and error handling.

In my workflow after  a request data action (this action changes the status of the item) I am using the Delete all the attachments UDA.

It is deleting the list attachments perfectly but it deleting the next task and throwing error below

8/28/2015 6:42 PM Error The workflow could not update the item, possibly because one or more columns for the item require a different type of information. Unknown error

I am trying to capture the error when UDA is completing and adding log history after that.

 

Though I have created a separate workflow and used the same UDA it worked perfectly fine.

Could you please help me with this.

Friday, August 28, 2015 10:34:30 PM

re: Nintex Workflow - Delete All Attachments UDA

Hi Ashish,

I'm afraid I don't know what is causing that. You'll need to do some debugging to get to the bottom of it.

cheers,

Vadim

Tuesday, February 9, 2016 10:21:29 AM
Vignesh
Gravatar

re: Nintex Workflow - Delete All Attachments UDA

Hi,

 

I am getting below exception error.

 

'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.

 

Thanks,

Vignesh Natarajan

Tuesday, February 9, 2016 10:51:33 AM

re: Nintex Workflow - Delete All Attachments UDA

Hi Vignesh,

there is some sort of error in the SOAP packet.  You need to look at it and make sure the data you are putting into the packet, isn't breaking the SOAP structure.

Vadim

Wednesday, February 10, 2016 1:49:01 AM
Vignesh
Gravatar

re: Nintex Workflow - Delete All Attachments UDA

Vadim,

 

How can I do that? I am not much aware of SOAP..

 

thanks,

Vignesh

Friday, February 12, 2016 1:47:23 AM
Vignesh Natarajan
Gravatar

re: Nintex Workflow - Delete All Attachments UDA

Hi Vadim,

 

Thanks. the issue is resolved.

 

thanks,

Vignesh

You must sign in to this site to post comments.
Already Registered?
Sign In
Not Yet Registered?
Register
  • RSS





 

Statistics

  • Entries (239)
  • Comments (1722)

Categories