locked
How to get the field being changed from sharePoint "ItemUpdated" ? RRS feed

  • Question

  • I have the sharePoint event handler like this,

    public override void ItemUpdated(SPItemEventProperties properties)
    {
    //Send a mail once the "Status" field  changed.
    }

    this method only will send a email if the sharePoint list's "status" field changed, will not be sending emails if any changes happens for other fields... I need to fire the event handler only when "status" field changes. how I can do this. now event is firing whenever I make changes to any field.

    Any idea.
    Vimal

    • Moved by Mike Walsh FIN Friday, June 18, 2010 7:35 AM not general (From:SharePoint - General Question and Answers and Discussion (pre-SharePoint 2010))
    Friday, June 18, 2010 7:21 AM

Answers

  • You need to work with After and Before Properties as shown in below example, thus based 
    on change you can cancel the event.

    public override void ItemUpdating(SPItemEventProperties properties)
    {
       if (properties.BeforeProperties["column"] != properties.AfterProperties["column"])
      {
        properties.Cancel = true;
        properties.ErrorMessage = "This column cannot be changed";
      }
    }

    Source http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=25

    Thanks
    Akhilesh Nirapure
    Friday, June 18, 2010 8:20 AM

All replies

  • You need to work with After and Before Properties as shown in below example, thus based 
    on change you can cancel the event.

    public override void ItemUpdating(SPItemEventProperties properties)
    {
       if (properties.BeforeProperties["column"] != properties.AfterProperties["column"])
      {
        properties.Cancel = true;
        properties.ErrorMessage = "This column cannot be changed";
      }
    }

    Source http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=25

    Thanks
    Akhilesh Nirapure
    Friday, June 18, 2010 8:20 AM
  • Thanks Akilesh

    it never go inside "IF" loop as properties.BeforeProperties["Offer Status"] and properties.AfterProperties["Offer Status"] are null aways regardless of what the fields value I change.

     

    Thanks 

    Vimal

    Friday, June 18, 2010 9:44 AM