views:

102

answers:

2

I'm writing a workflow that needs to perform certain actions depending on which fields are changed when someone edit's an item. For example, if a user goes in and removes a role (job) from an item (staff member) then I need the workflow to realise that the role field was changed, deduce which role was removed (or potentially added) and then notify the manager of that role and do any other necessary tasks. Another example would be if the address fields in an item get changed then the appropiate HR department need to be notified of the change.

To do this I'm going to try a code block when the workflow is started that compares the top two history entries and any fields that differ will be flagged as changed and I'll take the appropriate actions dependent on each field.

Could anyone please tell me what the other options are for getting this functionality as I'd like to know if there's a better way. Thanks

A: 

Using SPD workflows it would not be that hard, depending on number of roles.

Create a column and then go into the content type and hide it. Create a SPD workflow that executes on new or change. Compare the hidden column and the one the user entered, if changed compare values against a role name and do what needs to be done. When that is done copy the user entered column into the hidden column.

Ugly and long but if you don't have the abaility to get workflow code implemented on the server, thanks corporate IT, then it is an option.

Will Dieterich
A: 

I would enable versioning on the list and then use:

SPListItem currentItem = workflowProperties.Item;
SPListItemVersion previousItemVersion = currentItem.Versions[1];
//Compare the fields in currentItem and previousItemVersion

But if i understand your question correctly, that’s what you’re about to do already.

JMD