Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

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

share|improve this answer
    
I really like this solution. The check for the custom property stops recursive calls from PreUpdate > Update > PreUpdate > Update etc. Nice one –  Jaap Vossers Jun 2 '10 at 11:26
    
Glad you liked it! –  Renzo Jun 2 '10 at 12:07
add comment

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?

share|improve this answer
    
Yes that is what happening and I want to stop it. –  TheVillageIdiot Apr 7 '10 at 8:38
add comment

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;   
    }
}
share|improve this answer
    
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? –  Steve Lineberry Apr 7 '10 at 12:40
    
@Steve IAlertNotifyHandler.OnNotification is not called when alert subscription is created it is called when actual alert is sent. –  TheVillageIdiot Apr 7 '10 at 12:42
    
Yea, that's what I figured when I re-read your question. Thanks. –  Steve Lineberry Apr 7 '10 at 12:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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