Revert (or undo saved changes) a WorkItem to an older version in TFS API

Go To StackoverFlow.com

3

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

4)Save

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

2012-04-03 19:53
by user1060500


2

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.

http://geekswithblogs.net/TarunArora/archive/2011/08/21/tfs-sdk-work-item-history-visualizer-using-tfs-api.aspx

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

2012-04-03 22:23
by Tarun Arora
Not a total solution, but enough to get people well on their way to implement it. :) Thanks. - user1060500 2012-04-10 17:23


0

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:

enter image description here

2012-04-03 21:23
by Mohamed.Radwan -MVP
Yeah. Another option would be write my own deep clone routine to update existing workitem with values from old revision. Not going to go down this route. I am able to solve the problem without needing to revert at this point : - user1060500 2012-04-03 21:41


0

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.

2012-04-05 00:26
by Qwerty
Ads