Friday, November 13, 2015

Adjusting Email Notifications For SharePoint 2013 Task Lists

When looking at the settings of a SharePoint 2013 task list you no longer have the option to enable email notifications.  This used to be found under List Settings -> Advanced Settings -> Send e-mail when ownership is assigned. 

This is what it looks like in 2010.

image

This can be still be turned on using Powershell in SharePoint 2013.  Here is the powershell to perform that task along with a link back to the source of the script.  Thanks to the creator of the script karimSP!

$site=Get-SPSite "http://sharepoint2013/"$web=$site.OpenWeb()
$list=$web.Lists.TryGetList("Tasks")
if($list -ne $null)
{
$list.EnableAssignToEmail =$true
$list.Update()
}

Adjusting when the assigned to task email is fired

As it states in the 2010 settings, this will send an e-mail when ownership is assigned or when an item has been changed.  In a high transactional task process (automated task creation as example) this could lead to an incredible amount of emails.  Fortunately we have the ability to change the types of event that fire these emails in powershell.  The primary use case I used this for is too only send task emails on creation of the item (Add). 

The available options for when notifications are sent are listed in the SPEventType enumeration and they are:

Member Name Description
Add Additions to the list or list item. (0x00000001)
Modify All changes made in a list or list item. (0x00000002)
Delete Deletion of a list or list item. (0x00000004)
Discussion Changes in Web discussions. (0x00000FF0)
All All events pertaining to the list or list item. (-1)

 

Powershell to update the events

I have included variables at the top of the script that you can enter depending on the location of the task list(s) along with which ones you want to update.  Make sure you run the powershell to activate the assigned to email, the script above, prior to running this script.

################################################################### NAME: SharePoint2013TaskAlertEventTypes.ps1
# DESCRIPTION: Script to adjust SharePoint 2013 task list email notifications on different events
#
AUTHOR: Drew Madelung
#
LAST UPDATED: 11/11/2015
#
#################################################################

# ***IMPORTANT*** The powershell to enable assigned email notifications must be done prior to this script being ran

Add-PSSnapin Microsoft.SharePoint.Powershell

# Set variables - EXAMPLE variables are set
$sitecollectionUrl = "http://sharepoint2013"
# Eventtypes can be: All, Add, Modify, Delete, Discussion
$eventType = "Add"

# Optional variables - if not used, all event types for all assigned to task alert email notifcations on the listed site will be updated
$subsiteUrl = "/subsite"
$listUrl = "lists/tasks"

$site = Get-SPSite $sitecollectionUrl

# Get subsite if entered
if ($subsiteurl -eq "") { $web = $site.OpenWeb() } else { $web = $site.OpenWeb($subsiteUrl) }

$a = $web.Alerts

foreach ($alert in $a)
{
$alerttemplate = $alert.DynamicRecipient
if ($alerttemplate -eq "AssignedTo") {
if ($listUrl -eq "") {
$alert.EventType = [Microsoft.SharePoint.SPEventType]::$eventType
$alert.Update()
Write-Host 'Updated event type to' $eventType 'for the list' $alert.list
}

else {
if ($alert.ListUrl -eq $listUrl) {
$alert.EventType = [Microsoft.SharePoint.SPEventType]::$eventType
$alert.Update()
Write-Host 'Updated event type to' $eventType 'for the list' $alert.list
}
}
}
}
$web.Dispose()
$site.Dispose()

Link to download powershell script

SharePoint2013TaskAlertEventTypes.ps1

If anyone has any thoughts or suggestions for this script please let me know!

Originally Posted

Adjusting Email Notifications For SharePoint 2013 Task Lists


by Drew Madelung via Everyone's Blog Posts - SharePoint Community

No comments:

Post a Comment