views:

33

answers:

2

I've implemented IAlertUpdateHandler interface in a class and used it for handling creation and updating of alerts. The code is fired but it goes into endless loop by calling itself again and again.

Actually I want to suppress email notification so I'm calling a.Update(false); but this again calls PreUpdate or PostUpdate method and there is StackOverFlowException :(

I've tried returning true/false from both the methods but nothing is helping.

A: 

According to the documentation, you're supposed to just return true or false. Try commenting out the Update call and just return either true or false. If you call Update, you'll just go into the recursive loop and your return statement will never get evaluated.

Hirvox
@Hirvox it says **A Boolean value that can be used to prevent the update or to throw an SPException.** I don't want to prevent update, just to suppress subscription created email.
TheVillageIdiot
A: 

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