Event handlers, workflows and checking previous state without versioning in Sharepoint

Event handlers, workflows and checking previous state without versioning in Sharepoint

This might seem obvious, but it took me a bit bu surprise. Perhaps I should be embarrased.

Anyways, problem statement: How do you check a previous state of a field when an item is updated? Easy if you have versioning, but that only applies to document libraries. What about custom lists? No luck with versioning.

It would be really cool to use beforeProps, at least in ItemUpdating(), but alas, it is empty for anything but document libraries with versioning turned on.

What I end up doing is create a separate field in the list, called beforefield (where field is the name of my field, ie beforeState or beforeSum). In my event handler I then do:

if (item["Field"] != item["beforeField"]) // ie. changed
{
 doStuff();
 //...
 item["beforeField"] = item["Field"]; // new value set to beforeField
 item.Update();
}

Would be better if this was somehow included in SharePoint, though. This is a hazzle if you have many fields to check. You need a bunch of extra fields, the beforeFields, and if you just use the web interface to create lists instead of CAML and list definitions, you cant hide the fields from any nosy users.

Found this article valuable? Want to show your appreciation? Here are some options:

a) Click on the banners anywhere on the site to visit my blog's sponsors. They are all hand-picked and are selected based on providing great products and services to the SharePoint community.

b) Donate Bitcoins! I love Bitcoins, and you can donate if you'd like by clicking the button below.

c) Spread the word! Below, you should find links to sharing this article on your favorite social media sites. I'm an attention junkie, so sharing is caring in my book!

Pin It