Nintex Workflow 2010 - Multiple Dynamic E-Mail Attachments

We have a Nintex Workflow and I need to send a list of documents in a folder to a customer as email attachment. Sound easy !!

Although this could be an easy tasks unfortunately I couldn't find an easy way to do this, because the "Attachment" input element only takes a full path to a single file.

That means you can't loop through a folder and collect all files with a seperator in a variable and give it to the attachment control. Or better would be to collect all paths in the "Collection" variable and give this variable to the attachment control. This also does not work in my Nintex version. Maybe the Nintex guys already added this feature.

The only way I found is to save each file in a separate variable. So I had to make a restrictions like, "I've maximum 5 attachments".

So in my Workflow I've 3 variables (you can have more):

  • fileAttachPath: Contains the path to the folder like http://sharepoint/sites/projectX/docs
  • fileAttach1: is initialized with fileAttachPath (single line of text)
  • fileAttach2: is initialized with fileAttachPath (single line of text)
  • filesCollection: a collection variable to hold the files
  • fileToAttach: Need when we loop throught filesCollection (single line of text variable)

We initialize the variables fileAttach1/2 with fileAttachPath because an empty variable would cause an error in the email attachment. See http://connect.nintex.com/forums/thread/18201.aspx.



Now we have a list lookup task which loops through the list and writes the names of the files into a collection variable



Now comes a tricky one. We have to write the attachments into the variables. We need "For Each" task. We loop through the "filesCollection" variables and write each item into the filesToAttach variable.



Next we use "Run If" task to fill our variables. We begin with the highest variable, im my case "fileAttach2".
The condition is:

  • Check if fileToAttach = fileAttachPath and
  • fileAttach1 is not fileAttachPath

If we had more than 2 attachments we would check the prior one.



If this is successfull fill the variable fileAttach2 with the path to the file:




The last check is the one for the variable fileAttach1.



Now we can add the variables as attachments to any email in Nintex.

Here a look to the workflow diagram  (It's in german but it should be clear)



If someone found a better way, comments are appreciated.



Comments

Popular posts from this blog

Open SharePoint 2010/2013 Display, Edit, New Forms in Modal Dialogs

Ways to redirect http requests in SharePoint

Using WebDav on IIS 7 to access UNC Paths