Alerts are an essential method of keeping the lines of communication open between colleagues, but the default SharePoint Alert template most likely does not meet all your company’s needs. This is where from Discussion Board Plus comes in. Did you know that with Discussion Board Plus, you have the ability to modify the layout and tailor the manner in which the information is displayed in order to meet your business needs? By modifying the Alert Template file, you can make a variety of changes, including but not limited to: text color; add a button/link; and embed an image and corporate privacy policy. In this article, I will demonstrate how you can modify the alert template modifying the server-side template file.
Summary:
Among the server-side files, there is an XML file called Alerttemplates.xml that is used default to define the format, contents, and properties when a user creates alert messages from each SharePoint list type. SharePoint provides server administrators with the ability to customize this alert template, then deploy it using the stsadm -o updatealerttemplates command.
NOTE: Changes discussed in the following article will affect lists of type Discussion Board and Discussion Board Plus.
Steps:
In this article, I will demonstrate how you can change the font color from blue to red, and add links to Flat View, Thread View, or Append View for a Discussion Board Plus list in Alert mail.
Traditional alerts produced SharePoint provide the following information:
To modify the contents of the AlertTemplates.xml file, complete these steps:
- Create a working copy of AlertTemplates.xml.
Note: It is strongly recommended that you make a copy of Alerttemplates.xml, and make the changes in the new file, as any update from Microsoft could overwrite your changes in the original file.
Note also: Discussion Board Plus does not modify this file directly so, as a result, your changes will not be affected future Discussion Board Plus product upgrades.
On one of your Web Front-end servers, go to ‘%Program Files%Common FilesMicrosoft SharedWeb Server Extensions14TEMPLATEXML’ and locate the Alerttemplates.xml file:
Copy this file and rename it, giving it a new name. For this article, we will call it NewTemplates.xml:
- Edit the working copy that you just created.
Note: You can use any XML editing tool to edit the templates. I use Notepad to open it.
- We now need to locate the appropriate section of the file to modify. Each list type (Calendar, Tasks, Contacts, etc.) has its own section within the file that defines the layout and content of the alert. To modify Discussion Board Plus alerts, we want to locate the following tag:
1: <AlertTemplate Type="List" Name="SPAlertTemplateType.DiscussionBoard">
In this example, I want to modify and add links to the bar on the top of the alert. To do so, we will locate the following section of code:
1: <Default>
2: <HTML><![CDATA[
3: ss="toolbarbutton"><a href="]]></HTML><GetVar Name="ItemUrl" URLEncodeAsURL="TRUE" />
4: <HTML><![CDATA[">$Resources:Alerts_link_view; ]]></HTML><GetVar Name="ItemName" HTMLEncode="TRUE" /> <HTML><![CDATA[</a></td>
5: ss="toolbarsep">|</td>]]></HTML>
6: </Default>
And replace it with the following:
1: <Default>
2: <!--View Properties-->
3: <HTML> <![CDATA[ <td class="toolbarbutton"><a style="COLOR: red" href="]]> </HTML>
4: <GetVar Name="ItemUrl" URLEncodeAsURL="TRUE" />
5: <HTML><![CDATA[">View Properties: ]]></HTML>
6: <GetVar Name="ItemName" HTMLEncode="TRUE" />
7: <HTML> <![CDATA[</a></td> <td class="toolbarsep">|</td>]]> </HTML>
8: <!--Link to flat view-->
9: <HTML> <![CDATA[ <td class="toolbarbutton"><a style="COLOR: red" href="]]> </HTML>
10: <GetVar Name="ListUrl" URLEncodeAsURL="TRUE" />
11: <HTML> <![CDATA[/FlatPlus.aspx?RootFolder=/Lists/]]> </HTML>
12: <GetVar Name="ListName" HTMLEncode="TRUE" />
13: <HTML> <![CDATA[/]]> </HTML>
14: <GetVar Name="ItemName" HTMLEncode="TRUE" />
15: <HTML> <![CDATA[&FolderCTID=]]> </HTML>
16: <GetVar Name="RawValue#ContentTypeId" />
17: <HTML><![CDATA[">Flat View: ]]></HTML>
18: <GetVar Name="ItemName" HTMLEncode="TRUE" />
19: <HTML><![CDATA[</a></td>]]></HTML>
20: <!--Link to thread view-->
21: <HTML> <![CDATA[ <td class="toolbarsep">|</td> <td class="toolbarbutton"><a style="COLOR: red" href="]]> </HTML>
22: <GetVar Name="ListUrl" URLEncodeAsURL="TRUE" />
23: <HTML> <![CDATA[/ThreadedPlus.aspx?RootFolder=/Lists/]]> </HTML>
24: <GetVar Name="ListName" HTMLEncode="TRUE" />
25: <HTML> <![CDATA[/]]> </HTML>
26: <GetVar Name="ItemName" HTMLEncode="TRUE" />
27: <HTML> <![CDATA[&FolderCTID=]]> </HTML>
28: <GetVar Name="RawValue#ContentTypeId" />
29: <HTML><![CDATA[">Thread View: ]]></HTML>
30: <GetVar Name="ItemName" HTMLEncode="TRUE" />
31: <HTML><![CDATA[</a></td><td class="toolbarsep">|</td>]]></HTML>
32: <!--Link to append view-->
33: <HTML> <![CDATA[ <td class="toolbarbutton"><a style="COLOR: red" href="]]> </HTML>
34: <GetVar Name="ListUrl" URLEncodeAsURL="TRUE" />
35: <HTML> <![CDATA[/AppendView.aspx?RootFolder=/Lists/]]> </HTML>
36: <GetVar Name="ListName" HTMLEncode="TRUE" />
37: <HTML> <![CDATA[/]]> </HTML>
38: <GetVar Name="ItemName" HTMLEncode="TRUE" />
39: <HTML> <![CDATA[&FolderCTID=]]> </HTML>
40: <GetVar Name="RawValue#ContentTypeId" />
41: <HTML><![CDATA[">Append View: ]]></HTML>
42: <GetVar Name="ItemName" HTMLEncode="TRUE" />
43: <HTML><![CDATA[</a></td><td class="toolbarsep">|</td>]]></HTML>
44: </Default>
The content of the alert is defined between the tags:
1: <AlertTemplate Type=”List” Name=”SPAlertTemplateType.DiscussionBoard”>
…
1: </AlertTemplate>
For additional details about modifying the contents of the alerts file, refer to the MSDN Article AlertTemplates Schema.
- After modifying the new AlertTemplate file, we will use the stsadm command to write the changed templates into the database.
Note: These tasks require the currently logged-in account have DBAdmin rights to the SharePoint Configuration database.
Open a command window and enter:
1: cd "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14BIN"
Next run the command:
1: STSADM -o updatealerttemplates -url <http://urlname> -filename <your working copy filename>
For example:
1: stsadm -o updatealerttemplates -url "http://serverchauo14" -filename "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATEXMLNewTemplates.xml"
2:
Finally, schedule the timer job to execute the request:
1: stsadm -o setproperty -pn job-immediate-alerts -url <http://urlname> -pv "every 1 minutes"
2:
For example:
1: stsadm -o setproperty -pn job-immediate-alerts -url "http://serverchauo14" -pv "every 1 minutes"
2:
- Restart IIS.
Note: It may also be necessary to restart SharePoint Timer Services.
- Create a Thread or Post in a Discussion Board Plus list, and go to your mail to check Alerts. You will see new changes.
Now, you will see the flexible views for Thread such as Flat View, Thread View, Append View in red as pictured below:
See Also:
- Customizing Alert Templates in SharePoint Foundation 2010 [SharePointDevWiki]
- How To: Customizing alert emails using IAlertNotifyHandler [MSDN]