Sharepoint OnWorkflowItemChanged before / after property list
I would like to use the OnWorkflowItemChanged event in a WSS 3.0 State State workflow to check the changes made to the list item that started the workflow. The properties of this event include properties before and after the change, and I can bind to the after properties without any problem and get a set of properties with the changed values โโof the list item. However, the binding before properties is always empty and after some research I found this one http://msdn.microsoft.com/en-us/library/aa979520.aspx which states that properties are only available in document libraries and not lists.
What I would like to know if there is a workaround for this missing functionality or what would be the best approach to get this functionality?
a source to share
I am currently using the following workaround and would like some feedback on what others think. Personally, I don't like this as I think there must be a way to access this information provided by the framework.
I have created a custom execution code action in the initialization state of the state that waits for an item to change. The following code stores the properties in a workflow field for access after an update has occurred.
SPListItem item = workflowProperties.Item;
item.Update();
beforeApplicationChangedProperties = new Hashtable();
foreach (SPField field in item.ContentType.Fields)
{
if (!beforeApplicationChangedProperties.ContainsKey(field.Title))
{
beforeApplicationChangedProperties.Add(field.Title, item[field.Id]);
}
}
What do others think?
a source to share
What I overcame this problem was to use the previous version of the element. Of course, version control should be included in the list.
// get an object referencing the item in the list
Guid listGuid = new Guid(listId);
SPList myList = web.Lists[listGuid];
SPListItem myItem = myList.GetItemById(itemId);
// make sure there is at least one previous version to compare
// 0 -> current version
// 1 -> previous version
// 2 -> older version
// ...
if (myItem.Versions.Count > 1)
{
SPListItemVersion newItem = myItem.Versions[0];
SPListItemVersion oldItem = myItem.Versions[1];
}
a source to share