jueves, 12 de enero de 2012

Alertas custom Sharepoint 2010

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 (1). 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

 

Fuentes:

http://sharepoint2010funfacts.blogspot.com/

https://www.nothingbutsharepoint.com

http://www.sharemuch.com/2010/08/15/creating-custom-list-alert-templates-in-sharepoint-2010/

Más información:

http://msdn.microsoft.com/en-us/library/bb897925.aspx

(1) http://msdn.microsoft.com/en-us/library/bb802738.aspx

http://blogs.msdn.com/b/sharepointdeveloperdocs/archive/2007/12/07/customizing-alert-notifications-and-alert-templates-in-windows-sharepoint-services-3-0.aspx

http://neganov.blogspot.com/2011/08/custom-alerts-in-sharepoint-templates.html

No hay comentarios:

Publicar un comentario