Lars Nielsen's Discoveries

January 20, 2011

Only e-mail when task is assigned, not when it changes

Filed under: Customization,Development,SharePoint — Lars Nielsen @ 3:16 pm
Tags: ,

One complaint that end users sometimes mention about the workflows in SharePoint, even the built-in workflows, is that they are flooded with auto-generated e-mails about their task.

If you’re developing your own workflow, or if you use for example the Approval built-in workflow, then you need to tell the workflow what tasks to use when you associate the workflow with a list or content type. The list is set up to send an alert to the “Assigned To” person (or group – did you know you can assign a task to a SharePoint group? Very useful. Everyone in the group gets an e-mail to say they have been assigned the task). The alerts come for every change to the task, when it’s first assigned, when it’s completed, when it’s deleted.  At minimum everyone who is assigned the task gets 2 emails.  But you can change this so that they get only one: the “You have been assigned a task” e-mail.  Often, that’s all they need.

To do this you need to change the alert on the task list.  This is created automatically by SharePoint.  You can use SharePoint Manager to change it manually.  But you can also do it programmatically, for example in a feature OnActivated method so that it runs every time you activate the feature.

Here’s a method you can use to reset the task alerts so that it only alerts use when they are assigned a new task:

/// <summary>
/// Set the alerts for a task list so that it only sends alerts for new tasks assigned, not when
/// tasks are updated or completed. This reduces the e-mail traffic related to tasks
/// </summary>
/// <param name="web" />Site that contains the task list
/// <param name="taskListName">Display name (title) of tasks list
/// <returns>True if changed, false if no relevant alerts were found</returns>
public static bool SetTasksAlertsToNewOnly(SPWeb web, string taskListName)
   bool result = false;
   SPAlertCollection alerts = web.Alerts;
   foreach (SPAlert alert in alerts)
      if (taskListName == alert.List.Title)
         alert.EventType = SPEventType.Add;
         result = true;
   return result;



  1. Am I need to use Visual Studio and paste this code on it?

    Comment by Florence — August 8, 2016 @ 6:30 am

  2. Hello there. Yes you’d need to use Visual Studio to create for example a SharePoint feature and then add this method and a call to the method from the OnActivated event handler, or some other event handler.

    Comment by Lars Nielsen — August 8, 2016 @ 9:14 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: