TFS Work items do not expose their Events unless they are specifically subscribed for. Hence, we encounter many scenarios where we are limited to using work item field values for further use case enhancement.
For example, let’s say we have a scenario where we have a new work item “Request” and it is required that the email is sent to the Requester (work item Creator) and multiple people in “cc” field, whenever there is any change in the “State” field of the work item.
TFS provides Alert Explorer where user can define the email ids of users to be notified, whenever there is any change in a particular work item or notify [ME] whenever there is any change in the work item created by [ME].
If it is required that every time a work item field “State” is changed, an email should be sent to the people whose alias is selected at the run time, the TFS alert definition fails to do so.
By default, the TFS does not provide a multiple value selection in a drop down for selecting multiple people to be notified.
- Multi value control solution from codeplex can be used for defining multiple value selection in drop down box for cc field.
OR else, we can also define field “cc” as text field where we can provide semi colon separated email ids.
- Now, we are required to write a WCF Service and subscribe to the TFS 2010 Event Service.
These are the events available to which we can subscribe our WCF Service.
- Subscribe the WCF Service for “WORKITEMChanged “event.
"C:\Program Files\Microsoft Team Foundation Server 2010\Tools\bissubscribe" /eventType WorkItemChangedEvent /address http://localhost:1001/<WCF Service>.svc /collection http://localhost:8080/tfs/DefaultCollection
Every time a work item is edited, TFS generates an alert on the service for “WORK Item Changed “event. This WCF Service will listen to these generated events and pick up the work item id of the work item that has been modified.
- Extract the details of the work item from the work item store service, see the history of the work item and compare State “Old value” and “New value” to validate if there is any change in the “State” field.
- If the change has occurred, get the value for “CC” field and use SMTP Server to send email to the semicolon separated email ids.
Thus, writing a WCF Service and subscribing it to TFS Events enables us to extend our use case and play around with the values of attributes in our own way.
Below is a screen shot of the work item "Request" where we have “People CC” having semi colon separated multiple email ids and “Requester” alias to be notified for any change in “State” field.