Updating existing alert subscriptions in SharePoint 2010

by zebsadiq 13. January 2012 11:43

One of the annoyances about SharePoint alerts seems to be that the functionality of an alert template and existing subscriptions on an existing list, seem to be disjointed. When you update an alert template property for an existing list, the change is not applied to any existing alert subscriptions on that list. As a follow up to my previous post SharePoint 2010 custom alert template, I will try to describe the limitations and issues surround existing alert subscriptions and the options available to work around them.

Example of the problem: Suppose there exists an ‘Announcements’ list in a SharePoint site, Steve, a user on the site, subscribes to receives emails when there are changes made to the Announcements list. At this stage, Steve will receive the standard SharePoint out of the box announcement alert email every time there is a change made to Announcement list. All good so far. Then the site administrator decides that he or she wants to customise the look and content of the Announcement list’s email alerts, to perhaps make it fit the company’s brand guidelines. Work is done to create and add a new custom alert item style (as described in: SharePoint 2010 custom alert template). Then Bob, a new employee joins the company, and also subscribes to receive alerts on the Announcement list (after the alerts template customisation has been deployed).

Result: Bob receives the newly branded alerts email, however Steve still receives the old email format. Undesired result for most people!

This is because the alerts template information is cached per subscription. When the alert template is updated for a list, it does not automatically inform any existing subscriptions, hence the difference between what Bob receives and what Steve receives.

There are two ways in which Steve’s subscription can be updated to use the new alerts template.

a) Ask Steve to delete the existing subscription and re-subscribe. A major problem with this is that in a real scenario, there may be hundreds, if not thousands of Steves on this SharePoint site (not people with the same name Smile but rather people who had subscribed to the Announcements list  prior to the alerts template customisation). I consider this a bad idea.

b) Run a PowerShell script (Recommended) to update all existing subscriptions for the Announcements list. This is the fastest, easiest way to do it, but requires the SharePoint administrator to understand, modify and run the PowerShell script.

The script:

The administrator executing this script must 1) Understand what its doing 2) Gather accurate information required by the script (such as list paths and template names). This may require the administrator to talk to the developer who made the custom alerts customisation. 3) Make sure that the script will only affect the specific subscriptions that require manipulation. This requires a bit of investigation into how unique these list subscriptions are and a bit of common sense. 4) Have sufficient SharePoint and local privileges on the SharePoint server.

add-pssnapin Microsoft.SharePoint.PowerShell -erroraction silentlycontinue
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$AlertsTemplateCollection =  new-object Microsoft.SharePoint.SPAlertTemplateCollection($contentService)

$spWeb = Get-SPWeb -Identity http://yoursitecollectionroot/


$alerts = $spWeb.Alerts
 
# if more than 0 alerts, iterate through these alerts to see if there is one for the user
if ($alerts.Count -gt 0)
{
	$myalerts = @()
	foreach ($alert in $alerts)
	{
		if (($alert.AlertTemplateName -eq "EXISTING TEMPLATE NAME OF THE TARGET TEMPLATE e.g. 'SPAlertTemplateType.Announcements'") -and ($alert.ListUrl -eq "RELATIVE PATH TO YOUR LIST e.g. 'Lists/Announcements'"))
		{
				echo "Updating" + $alert.AlertTemplateName
				$alert.AlertTemplate = $AlertsTemplateCollection["YOUR_UNIQUE_TEMPLATE_NAME_VALUE"]
				$alert.Update()
				echo "Updated $alert.AlertTemplateName"
		 }

		
		
	}
}


$spWeb.Dispose()

You can modify this script to be more specific. Maybe you have two lists of the same alerts template type in the same SharePoint web. You have to be careful not to update subscriptions for lists which are not supposed to have a custom alert template. Perhaps you can check for a certain list path for every subscription. Everyone’s requirements for this are going to be unique. The important thing is to think about this in detail. Plan your testing for this procedure in a test environment, so that you can be confident that this will deliver the correct results on your live server.

Warning: If anyone is contemplating whether to just update the relevant SQL table to stay in their comfort zone, STOP! You should never make changes directly to the SharePoint database. This is not supported by Microsoft and Microsoft may revoke their support for your SharePoint installation if you go ahead with this.

Comments

13/01/2012 20:54:56 #

SharePoint 2010 custom alert template

SharePoint 2010 custom alert template

Zeb Sadiq | Reply

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Calendar

<<  March 2024  >>
MoTuWeThFrSaSu
26272829123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar