Monday, October 17, 2011

Custom Alerts in Sharepoint 2010

Alerts are automated emails generated by Sharepoint when something changes (a list item for example) and if any user has created an alert for that particular change in the list item.

In some scenarios, we may want to customize the alert email generated by the Sharepoint 2010. This can be done in two ways

1. Altering the OOTB alert template xml to use whatever the text you would like to have in the alert email
2. Adding a custom alert handler in the dll deployed to GAC and alter the alert template xml to make use of that

I personally prefer the second method since we (programmers) have more control over the email subject and body and I find it little complex to achieve my particular situation (altering the default url to link the edited/changed item).

Option 1:
To briefly describe the first option, the OOTB alert template files need to be modified. The template file can be found under {root}\TEMPLATE\XML\alerttemplate.xml. In this file you can find AlertTemplate for different list types. For my purpose I had to modify for the discussion lists (Name="SPAlertTemplateType.DiscussionBoard). Inside an AlertTemplate XML item, you will find two elements "Digest" and "Immediate" one for each type of alert. To retrieve additional fields when generating the alert message, modify "ImmediateNotificationExcludedFields" and "DigestNotificationExcludedFields" respectively and make use of those fields in the xml itself.

With that said, I have done only a basic research on the above method.

Option 2:
To have the modification done using the Second option, the above template file needs to be modified to tell the SharePoint to use a custom handler when generating alert emails.

Please COPY the original alerttemplate.xml file and work on the copy. DO NOT CHANGE THE ORIGINAL.
In the file add the reference to the custom handler that you created and deployed to GAC (I'll explain how to create the alert handler later)

Find the "Properties" node under the AlertTemplateType and add the reference like this

After updating, a powershell script needs to be run to update SharePoint to make use of the handler. Like this below.

After doing the update statement, the SharePoint services need to be restarted. To restart them, you can use the below PowerShell script

Thats it. After this the custom handler must be called whenever an aler email is generated based on all discussion boards

Custom Handler Creation:
Now. How to create the custom alert handler for SharePoint 2010. Below is a sample code for a simple alert handler

Hope this helps some one else.

Senthil S

1 comment:

  1. hi,
    I receive alerts by email and it's hard to reply a post (discussion board) on iphone because the "alert me" send an email with a link that take us to a "body view". It would be much easier if I received a link that could take me directly to "flat view"

    Can you help how to to that?