SPAlertHandlerParams - not behaving correctly for daily alerts


  • Here is my alert handler code (slightly modified for posting here, so may not be perfect):

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Utilities;

    namespace MyFunkyNamespace
    public class AlertHandler : IAlertNotifyHandler
    public bool OnNotification(SPAlertHandlerParams ahp)
    // N.B. before debugging this class, make sure you have
    // restarted the SP timer service to pick up latest copy of the dll
    using (SPSite site = new SPSite(ahp.siteUrl + ahp.webUrl))
    using (SPWeb web = site.OpenWeb())
    SPList list = web.Lists[ahp.a.ListID];
    for (int i=0; i < ahp.eventData.Count(); i++)
    SPListItem item = list.GetItemById(ahp.eventData[i].itemId);
    foreach (SPField field in item.Fields)

    return true;
    catch (Exception ex)
    return false;

    This code works great for immediate alerts. No problems at all. BUT, if you then go and define a daily alert, when the following line executes:

     SPListItem item = list.GetItemById(ahp.eventData[i].itemId);

    ... it will error because itemId is either 0 or some large integer number like 1634890341.

    Also if I try a quickwatch on ahp.a.ItemID, then it will throw an SPexception so you can't get it that way either.

    I have sharepoint SP1 installed and I have also tried installing kb957691 separately, as it mentions a bug with eventData (though this actually relates to another isssue).

    The only solution atm seems to be this horrible bit of code:

    int itemId = int.Parse(ahp.eventData[i].itemFullUrl.Substring(ahp.eventData[i].itemFullUrl.LastIndexOf('/') + 1).Replace("_.000", ""));

    I note that someone called Tom had exactly the same problem, as he has detailed in the community content here:

    I guess I have to escalate this one to MS, as it looks like a bug, plain and simple. However, I can't understand why no one else has had this issue with daily alerts.

    Btw, for testing daily alerts, you probably want to set the daily alert to fire quite shortly after you create an item, rather than waiting all day!

    To do that, create your alert via the UI, get the guid, then use code like this:

                SPSite site = new SPSite("http://localhost:81");
    SPWeb web = site.OpenWeb();
    SPAlert alert = web.Alerts[new Guid("723E1DD7-4A86-468D-BF59-24B0C5B475D4")];
    alert.AlertFrequency = SPAlertFrequency.Daily;
    alert.AlertTime = DateTime.Now.AddMinutes(1);

    • Edited by Mike Walsh FIN Monday, July 6, 2009 11:55 AM (MS BUG?) removed from Title. Adds nothing useful
    Friday, April 3, 2009 9:05 AM

All replies

  • "However, I can't understand why no one else has had this issue with daily alerts."

    Well, except Tom ;c)
    Friday, April 3, 2009 10:14 AM
  • Hi ,
    I have a question.How do i customize email body of the mail message sent when user is added in to the sharepoint group.
    I have created an alert handler to customize the alerts as given in the following link:

    I am abe to customize for Doumnet libraries and lists,but how i customize the email body of the mail send to user when added to group.

    when should i place the below piece of code ?



    NotificationHandlerAssembly>AlertHandler, Version=, Culture=neutral, PublicKeyToken=25e9470deef24e40</NotificationHandlerAssembly>







    • Edited by Mike Walsh FIN Monday, July 6, 2009 11:56 AM "Please help me,its very urgent." removed. Do NOT post urgent issues to forums. Instead use MS Customer Support Services / Premium Support or Partner Support (if you have those two latter ones)
    Tuesday, April 21, 2009 12:55 PM
  • Hello,

    I have the same problem.

    Unfortunately, I have no solution is found! Has anybody an idea?

    Greeting Maik
    Tuesday, June 30, 2009 9:54 AM
  • Hi ,

    We are facing the same issue. Please let me know if someone knows the solution.

    Please help ...
    Friday, July 3, 2009 6:48 AM
  • Hi all,

    I have also same issue and looking for solution but i don't have any solution of this.
    Has any one any solution of this problem? Please share solution if any one have.....

    Thanks in advance...
    • Proposed as answer by SP User Wednesday, August 19, 2009 10:55 AM
    • Unproposed as answer by Anjali Ch -MSFT Friday, July 16, 2010 6:02 PM
    Monday, July 6, 2009 11:37 AM
  • sorry ,by mistake i have clicked on propose as answer for the last comment.
    here is the answer for your question.

    you have to customize the layouts page called "aclinv.aspx".

    this page will be present in the layouts folder in the 12 hive.

    customize it and explicitly modify the email content.
    Wednesday, August 19, 2009 11:01 AM