1

Has anyone implemented IAlertUpdateHandler interface successfully?

Actually I've to suppress alert subscription notification email. I've following code in PreUpdate method:

public bool PreUpdate(SPAlert a, SPWeb web, bool newAlert, string properties)
{
    if (CHECK_IF_SUPPRESSING_EMAIL)
    {
        a.Update(false);
    }
    else
    {
        a.Update();
    }
    return true;//have tried returning false also
}

but I'm getting StackOverFlow exception as the method is called recursively. Any clues about what is going wrong?

EDIT:- I've tried using PostUpdate also but got same results.

1
  • Haven't really used this one yet, only aware that it exists. If you are calling a.Update() aren't you initiating a PreUpdate again? Apr 7, 2010 at 8:29

2 Answers 2

1

I know that it might be a bit late for this but I thought put it anyway to help the next one.

I found a solution/hack for this problem.

I beleive that when the alert is created from the UI the system fires an SPAlert.update(), so what I came up with is to do similar but ignore the update called from the UI to do that I added a custom property to the SPAlert property bag.

public bool PreUpdate(SPAlert a, SPWeb web, bool newAlert, string properties)
{
    if (CHECK_IF_SUPPRESSING_EMAIL && !a.Properties.ContainsKey("CustomUpdate"))
    {
        //add a property to identify this update
        a.Properties.Add("CustomUpdate", ""); //can be called anything :)
        a.Update(false);
        //return false to ignore the update sent by the UI
        return false;
    }
    else 
    {
       //no changes here proceed with custom behaviour
       return true;
    }

}

I have tested and it seems to do the trick hope this helps someone :)

Renzo

2
  • I really like this solution. The check for the custom property stops recursive calls from PreUpdate > Update > PreUpdate > Update etc. Nice one Jun 2, 2010 at 11:26
  • Glad you liked it!
    – Renzo
    Jun 2, 2010 at 12:07
0

I think you need to be using OnNotification in the IAlertNotifyHandler interface.

public bool OnNotification(SPAlertHandlerParams ahp)
{
    if (CHECK_IF_SUPPRESSING_EMAIL)    
    {        
        return false;    
    }    
    else    
    {        
        return true;   
    }
}
3
  • Oops, now that I re-read your question, I think you are trying to suppress the alert creation confirmation e-mail and not an alert itself. Is that correct? Apr 7, 2010 at 12:40
  • @Steve IAlertNotifyHandler.OnNotification is not called when alert subscription is created it is called when actual alert is sent. Apr 7, 2010 at 12:42
  • Yea, that's what I figured when I re-read your question. Thanks. Apr 7, 2010 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.