I am looking to create an "undo" mechanism for a TFS work item using the TFS API - this will undo committed changes. Basically, after saving new data (also using the API) to the work item, I would like the option to revert the WorkItem back to the previous version.
Pseudo code something like this...
1)Get current Work Item for Id:xxxxxx
2)Get "revision id" of this latest work item and store in "PreviousRevId"
3)Modify field values
5)For whatever reason we don't want these changes any more (domain logic as to reasons are excluded for brevity)
6)Revert to old revision ("PreviousRevId") and make it the current (latest) revision
Have a look at the Work Item History Visualizer i created. By taking the work item Id, you can pull out the history of all work item fields.
But this will only help you get the information, rest you'll have to build your own control to build the revert functionality.
EDIT: Also worth checking this visual studio extension ** http://visualstudiogallery.msdn.microsoft.com/d127b275-b7b6-4504-b01e-58b4a010ff53 This lets you see the work item as it was on the historic date. Giving you the baseline affect you are after. HTH
I don't think this could be achieved by SDK, you can do this against the DB directly but this is of course not recommended at all, anyway the main 2 tables to hold work items are WorkItemsWere and WorkItemsLates see the following:
There is no automatic way to revert, but it's an easy foreach loop to iterate through the fields to update them to the previous value. You also have to worry about links and attachments.