index > Team Foundation Server - Work Item Tracking > Custom History Control

Custom History Control


We would like to add a tab to the work items that is similar to the History tab in its functionality, but only lists times where the work item state transitioned and who did it.

I could figure it out by reading the database, but this isn't recommended since the DB schema could change. Also, I would need some way to perform a query when the work item's form is shown.

I could add a trigger to modify a custom field that contained the information, but again, the trigger would be referencing the schema. Also, I don't like adding to the database in this fashion.

If there is an event that is fired every time a work item is changed, I could have the event call a web service and let it modify a custom field if the state had changed. This seems to be the best option for future-proofing the solution.

Is there an event that is fired on work item changed? Is there some other option I am missing?

Thanks for any help.

Mike from ServiceLink

Mike,

If we are talking about modifying work items in Visual Studio, you could write Visual Studio add-in that will hook up onto work item events. I believe event that are of interest to you is Saving event of IWorkItemDocument interface. There you can change field values (according to your logic) before item is saved. Also, should you decide to do something every time field is changed before saving, there is Item.FieldChanged event in IWorkItemDocument, so you can review every user change as he edits work item.

The documentation on that is rather scant, but you can look at Naren Datha blog (entry1 and entry2) for some details. Should you have specific question, post them and I will try to answer.

Hope that helps,

Eugene




Blog at http://teamfoundation.blogspot.com
eugene.z

Looks like some good information. Only problem I see is it looks like that describes client-side addins. I would like to make my add-in to run on the TFS server so I don't have ensure the all the developers have it installed in order for the work items to get updated.

Mike from ServiceLink
Actually with the workitem object (in our workitemtracking object model) you can get revisions collection, and you can walk the revision collection from first revision to find all state transistions. This is the easiest approach. If you want eventing solution, check out http://blogs.msdn.com/narend/archive/2006/07/27/679571.aspx for details on creating a webservice to get triggered on a workitem change.


http://blogs.msdn.com/narend
Naren Datha - MSFT

Thanks for the info Naren.

One question though. I need to put this information on a tab on the bug work item form. Every sample form modification I've seen only allows you to show an existing field in the database. Is there a sample on how to execute a query and show its results on the form? Or would I need to write some kind of custom control like the history control, and is there an example of that?

Mike from ServiceLink
Mike, a query result cannot be shown in a control in workitem form. So you need to build a custom control. SP1 will have that functionality. I am hoping to upload few samples and few custom controls (such as a webbrowser control where you could display a web page in workitemform with custom information) in my blog after SP1 release. Beta for SP1 is expected soon.


http://blogs.msdn.com/narend
Naren Datha - MSFT

Ok, in the mean time, how about this?

1. I add a new field to the work item.

2. I subscribe to the workitemchanged event with a web service.

3. In the web service, I check if the state changed, and if so, I append text about the change to my added field from above.

4. I add my tab to the bug template, and display my custom field in the new tab.

Will this work? This is what I am trying to do right now, but I am getting an error trying to get the WorkItemStore.

...

WorkItemStore wiStore = null;

Microsoft.TeamFoundation.Client.TeamFoundationServer server = null;

WorkItemChangedEvent workItemChangedEvent = this.CreateInstance<WorkItemChangedEvent>(eventXml);

TFSIdentity tfsIdentity = this.CreateInstance<TFSIdentity>(tfsIdentityXml);

foreach (StringField sField in workItemChangedEvent.ChangedFields.StringFields)

{

if (sField.ReferenceName == "System.State")

{

server = TeamFoundationServerFactory.GetServer(tfsIdentity.Url);

wiStore = new WorkItemStore(server);

}

}

...

When I try to create the WorkItemStore, I get the error "Cannot complete the operation. An unexpected error occurred" which is less than helpful.

Mike from ServiceLink
I think this will work. You got to be careful not to end up in infinite loop where you change a workitem in event handler and that causes another event and your filter expression should be carefully crafted to prevent it. To use workitemstore in webservice, it needs to be configured correctly and the steps are at http://blogs.msdn.com/narend/archive/2006/07/29/682032.aspx . You can try those steps and let us know if you still get errors.


http://blogs.msdn.com/narend
Naren Datha - MSFT

Naren,

I wonder if the solution above gets implemented, would it be possible to convert it to custom control once SP1 is ready?

Thanks, Eugene




Blog at http://teamfoundation.blogspot.com
eugene.z
If you use webservice to do these changes, then I do not see a need to use customcontrols in SP1 (unless FieldControl or HtmlControl is not enough to show your data).


http://blogs.msdn.com/narend
Naren Datha - MSFT
reply 10

You can use google to search for other answers

 

More Articles

Using Excel as bug template
Strange Problem --- SQL Server 2005 and TFS and Team System
Exception on import: It was String, but now is HTML.
how to increase attachment upload limits for defects
Word crashes when connecting to TFS
limit control type links control to specific work - items
MS Project synchronization
Work Items Areas and the WOrk Item OM
Can I create new link types?
Accessing work item history from API
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

Area not refreshed in Work Items - TFS RTM
Add Users programatically
Looking for RASK Requirements Authoring.…
Work Item automated email
Default is fixed, once set, even if the …
Work Item - LISTITEM Value to return the…
Get all changesets number that linked to…
Problem logging in Team Foundation Serve…
How to e-mail users when WorkItems are a…
Localized web server instance not launch…
I would like to make a fount end browser…
Automatically create a work item during …
Problem with displaying "Work Items…
How can I add a work item whose type is …
Importing existing tasks into the new Te…

Hot Articles

Unpublished changes in Project
WSS issue list and TFS Work Items, any i…
Work Item to Work Item associations
Query results window is cached ?
Deleted AD resource causes publishing er…
How to track completed workitem
Readonly flag for System.ChangedBy field…
link work-items with other work-items , …
TFS and Project Server 2003
Web Client for WIT
What Is the Difference Between a Task an…
TF54000: Cannot update data because the …
Field value restrictions for different u…
getting associated changesets for work i…
How to force refresh of iterations on It…

Recommend Articles

Getting Associated work item for a chang…
Problem logging in Team Foundation Serve…
Http error when adding attachments to wo…
Work Item Access control based on Work I…
Task "WITs" from Group "W…
Subscribing to events
webservice subscription: URL authorizati…
How to track completed workitem
Default value for not listed values in d…
Publishing to TFS improperly changes Sav…
Creating a Custom query programmatically…
Global Lists & Default Values
How The TFS publish the build numbers us…
Event subscription filter - limited to S…
VS.NET command to add work items