Implementation of IAlertUpdateHandler

TheVillageIdiot
  • Implementation of IAlertUpdateHandler TheVillageIdiot

    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.

  • 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;   
        }
    }
    

  • 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

Related questions and answers
  • a Filtered Parameter. However the dropdown of parameters is greyed out and just says "No Parameters". Note: the web part I'm trying to connect to is also custom and may not have been fully completed and tested for providing a value via a connection. Is there anything that explains why I'm unable to set up a connection? Here is the code for my web part: public class ProgramEntityTokenConverter : WebPart, ITransformableFilterValues { public bool AllowAllValue { get { return true; } } public bool AllowEmptyValue { get { return false; } } public bool

  • (defaultproperties, '"sample"') ORDER BY "Rank" DESC Why are these queries not returning all 3 results? We have tried setting TrimDuplicates to false but it makes no difference. ... this only yeilds 1 result, say "Sample (test3)". If we change this to use a query as follows, then this also returns a single result. However this time the result is a different record, say "Sample

  • I've encountered the strangest problem. I've got two features: ContentTypes: contains a couple of custom fields and a content type (based on plain ol' 0x01) called Withdrawals that uses them... ID="0x0100B4366B5F6383463b8464DBD2EDD5E097" Name="Withdrawal" Description="Record of a team withdrawal" Hidden="False"> <FieldRefs> <FieldRef ID... xmlns:ows="Microsoft SharePoint" Title="Withdrawals" FolderCreation="FALSE" Direction="LTR" Url="Lists/Withdrawals" EnableContentTypes="TRUE" BaseType="0"> <MetaData> <ContentTypes>

  • Is there a way I can customize the alert subscription email sent to users when they subscribe (or their subscription added by System Administrator) to a list for Alerts? I've gone through Microsoft.Sharepioint.ApplicationPages.SubNewPage but the method that adds alerts is too cryptic :(

  • Using VS 2010 i've created BCS model for external MS SQL source, deployed it with success, then created external list - it works perfect. Now my task is - create visual web part in VS2010 and place sharepoint:ListView in it to display external list. See code for CreateChildControls() method: protected override void CreateChildControls() { // Control control = Page.LoadControl(_ascxPath); // Controls.Add(control); Microsoft.SharePoint.WebControls.ListView view = new Microsoft.SharePoint.WebControls.ListView(); SPList list = SPContext.Current.Web.Lists

  • What I want to achieve is something similar to this OOB method: SP.ListOperation.Selection.getSelectedList() But this method only returns the GUID of the selected list. I would like to get the path, so if the user has browsed to a subfolder of the list I want to retrieve the current list/folder path. How can this be done?

  • (I have also asked this question on Stack Overflow) I have a SharePoint feature I'm using to add some custom aspx files to the Pages Library. When I activate the feature, I can visit the pages in-browser and they are visible in SPDesigner, but when I "View All Site Content" they are not there. Why is this the case? The Feature's Elements File: <?xml version="1.0" encoding="utf-8"?> <...="Example.aspx" IgnoreIfAlreadyExists="False"> <Property Name="Title" Value="The Example" /> <Property Name="ContentType" Value="Page" /> </File> <

  • I am in a position where service credentials change quite a lot, I would normally use central admin to change the credentials but quite often the application pool that runs that is using the same credentials which I want to change. I've tried writing the following powershell script but I always get FALSE as the result of SetPassword. Any ideas what i am doing wrong? $login and $password are parameters which are passed in to the script. $managedAccount = Get-SPManagedAccount $secureString = convertto-securestring $password -asplaintext -force ##Set-SPManagedAccount -Identity

  • :internal"> <xsl:output method="html" indent="no"/> <xsl:decimal-format NaN=""/> <xsl:template match="/"> <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row...-of select="format-number(sum(for ($i in /dsQueryResponse/Rows/Row/@Distance) { return number(replace($i, ',','.')})), '#,##', 'european')" /> Tried this, but it fails (Failed setting...; I've got the XSLT above and it does provide output but with the following values in the Distance Column: 2 3,5 -1,3 0 I get a result different from NaN but not the sum, only the first value

Data information