Custom Alerts – Part 2 – Filters

In my previous post on how to customise Alerts, we could see how to change the html of an alert. In this post, I will show how to change the filter for an alert, which defines the conditions in which events cause and alert to trigger and an email sent.

Say for example we have a list with a field called “Assigned To”, and we want know when someone (other than yourself) changes the assignment on that list item.

If we open the custom alert XML file we created in the 12 Hive at C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\alerttemplates.xml, and search for our customised AlertTemplate node, we will find a section called Filters. Inside that node is a few different default FilterDefinitions, which specify the conditions for an alert to fire.

So we can create our own, give it a Friendly Name and Short Name, and define the conditions in a CAML query in the Query section. You can check compare the old and new values of an item using the field_name/Old and field_name/New structure.  See the picture below for an example.

 customalerts_5.jpg

Save and register the alert using

stsadm -o updatealerttemplates -url http://yoursite/sites/sitecollname -filename “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\alerttemplatesCustom.xml”

And set the Alert Template on the list by

SPList spList = null;spList = spWeb.Lists[listName];
SPAlertTemplate newTemplate = new SPAlertTemplate();
newTemplate.Name = “SPAlertTemplateType.MyCustomAlertType“;
spList.AlertTemplate = newTemplate;
spList.Update(); 

Now when you create an alert through the UI you will see your new filter appearing in the alert options.

customalerts_6.jpg

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: