views:

1432

answers:

2

I would like to use the OnWorkflowItemChanged event in a WSS 3.0 State machine workflow to check for changes made to the list item that kicked off a workflow. The properties of this event include before and after change properties and I can bind to the after properties with no problem and get a property set with the changed values of the list item. However the bound before properties are always empty and after some research I have found this http://msdn.microsoft.com/en-us/library/aa979520.aspx which says before properties are only available on document libraries and not lists.

What I would like to know is if there is a workaround to this missing functionality or what would be the best approach to get this functionality?

A: 

I have currently used the following workaround and would like some feedback as to what others think. Personally I don't like it as I think there should be a way of accessing this information provided by the framework.

I have created an execute custom code activity in the state initialization of the state which waits for the item to be changed. The following code saves the properties to a field within the workflow for access after the update has occured

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?

Simon Fox
+1  A: 

The way that I overcame this problem was by using the item's previous version. Of course, versioning must be enabled on 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];
}
Kit Menke