SPAlert Filter and DynamicRecipient properties

359 views
Skip to first unread message

Steinb...@gmail.com

unread,
Mar 2, 2007, 12:06:59 PM3/2/07
to
Hello, I'm trying to create Alerts programattically, and I can't find
much info on how to set the Filter and DynamicRecipient properties
(which are CAML strings).

I believe (correct me if I'm wrong) the DynamicRecipient property is
used to set who gets e-mailed as part of the alert. I'm not sure how
to write this string in CAML. I would just be adding users to the
alert, so a string would add j...@gmail.com and t...@gmail.com would be
great. If there's a way to specify a Sharepoint Group, even better (I
could just get an e-mail list through code for that, though, so it's
no biggie).


I believe (correct me if I'm wrong) the Filter is the property used in
the standard "Create Alert" UI when it asks you:
"Send me an alert when:
-Anything changes
-Someone else changes a document
-Someone else changes a document created by me
-Someone else changes a document last modified by me"

If I could just replicate that, that would be great.

Thanks for any help,
Chuck

gary

unread,
Apr 2, 2007, 9:52:36 AM4/2/07
to
I have the same problem, I want to add some other
CAML to filter, but it alwarys failed.

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com

Radu

unread,
May 1, 2007, 1:48:00 AM5/1/07
to

Radu

unread,
May 1, 2007, 1:51:02 AM5/1/07
to
For both things, look at existing examples
- for Filter, first create an alert filtered by an existing view's filter
- for Dynamic Recipient, set a Task list's email property to on

Once you examine in a debugger the Filter and Properties props of the
SPAlert objects, you should be able to construct similar ones pretty easily
and apply them to new alerts in your custom code

Radu


Radu

unread,
May 1, 2007, 2:39:00 AM5/1/07
to
Running this sample code, I can see existing filters and properties

SPSite site = new SPSite(strSite);
SPWeb web = site.AllWebs[strWeb];
foreach (SPAlert alert in web.Alerts)
{
Console.WriteLine(String.Format("Title:{0} Filter:{1}",
alert.Title, alert.Filter));
foreach (string p in alert.Properties.Keys)
Console.WriteLine(String.Format(" key:{0}val:{1}", p,
alert.Properties[p]));
}

For instance, the task list’s built in alert is particularly complex--it
compares the old versus the new values of a field (a view, by definition not
being associated with a change, can only look at current, a.k.a new values)

Title:System
Filter:
<Query>
<Or>
<IsNull><FieldRef Name="AssignedTo/Old"/></IsNull>
<Or>
<And><IsNotNull><FieldRef Name="AssignedTo/Old"/></IsNotNull><Neq><FieldRef
Name="AssignedTo/Old"/><FieldRef Name="Editor/New"/></Neq></And>
<And><IsNotNull><FieldRef Name="AssignedTo/New"/></IsNotNull><Neq><FieldRef
Name="AssignedTo/New"/><FieldRef Name="Editor/New"/></Neq></And>
</Or>
</Or>
</Query>

This is also a system alert, which means that there is no subscriber, but
instead it is sent to whoever is in the dynamicrecipient property, in this
case “AssignedTo”

You can set the spAlert.Filter and spAlert.Properties["dynamicrecipient"]
just as easily as reading them, then call spAlert.Update() (where spAlert is
just a generic name for a SPAlert object)

muktasharma

unread,
Jan 19, 2009, 12:34:31 PM1/19/09
to
Can I use this alert filter query to build a CAML query to filter the data in the same way using /New and /Old values.
I am trying to make a alert once I get the item changes through CAML query

Thanks

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com/default.aspx?ref=ng

Reply all
Reply to author
Forward
0 new messages