I have a workflow associated on a list with 6 columns that sends out mails when an attachment is attached to the list item. I made the workflow to run when an item is created and modified. If I attach another attachment to the same list item then the workflow runs which is well and good.

The major hickup in the workflow is, that it runs even if I change any one of the columns values. I don't want that to happen as its not correct.

Is there any way to make the workflow to run only when items are attached? Please suggest

2 Answers 2


Workflow is not good in this situation. The best practice is to use EventReceivers and handle the ItemAdding event.

The event has Before and After properties, so you can compare whether a new attachment has been added.

Then use SPUtility.SendEmail

  • I think you shouldn't recommend replacing WFs with event receivers without proper pros and cons analysis. OP didn't specify what WF technology is he using and this is very important factor when making a decision of switching from WFs to event receivers. Commented Dec 17, 2014 at 17:42
  • @SlavenSemper If you read the requirements, its clearly the job of an EventReceiver. Commented Dec 17, 2014 at 17:44
  • Not necessarily. Although your answer is technically correct, the easiest way to solve the issue is with event receivers, but, event receivers run in w3wp.exe process and they could potentially block the entire farm because of faulty code. On the other hand WFs 2013 live in their own process and if they break, they don't break the farm. Commented Dec 17, 2014 at 17:49
  • 1
    Ok, but I don't see its tagged under 2013? Also in Workflow how you can find the before and after properties of an Item? Commented Dec 17, 2014 at 17:52
  • It's a hassle but it can be done. For example, enable versioning and compare current attachment with previous version. Commented Dec 17, 2014 at 17:56

What I would do in this case is have another field that you are using to track the previous value of the attachment field.

This would be a true/false or single line of text field. You would hide it in your form either using infopath or content types or jQuery.

So let's say this field is called 'hasAttachment' you set the default value to false.

When the workflow runs you have the following process:

  1. Check the value of hasAttachment if it is false then continue the workflow if it is true then stop (note: you could also check to make sure the attachments weren't deleted).
  2. Check if there are list item attachments if true then
  3. Do your logic
  4. Set hasAttachment = true

With that process, it will run once when the attachments are added to the item and not any other items.

  • Hi Bryan, thanks for your inputs. I need to check if the column information is modified. If only the column information is modified then the mail should not trigger. Commented Dec 18, 2014 at 5:35
  • Exactly, so the above process is the negative of that, it checks to see if the attachment has changed, if it has(and there is a new attachment) then it would send the mail. Otherwise it would do nothing. Commented Dec 18, 2014 at 5:37
  • OK so that works for the first attachment. Now lets say that I'm adding another attachment to the same list item. Then it fails. My logic is: If CurrentItem:oldtitle equals false, then Email me and set oldtitle to True. Else Stop the workflow Commented Dec 18, 2014 at 6:23
  • Check this image link[link] Commented Dec 18, 2014 at 6:32
  • Finding additional attachments would be very difficult. Reason being, attachments in SPD only show true or false. You could examine every field and its previous value but even with that, someone could open the edit form and click save then it would kick off the workflow. If you MUST do this, I would add javascript to the page and an 'attachmentCount' field. I would have the javascript update the attachmentcount and then use attachmentcount and previousAttachmentCount in your workflow. Commented Dec 18, 2014 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.