New release of TFS Alerts DSL that allows work item state rollup

A very common question I am asked at clients is

“Is it possible for a parent TFS work item to be automatically be set to ‘done’ when all the child work items are ‘done’?”.

The answer is not out the box, there is no work item state roll up in TFS.

However it is possible via the API. I have modified my TFS Alerts DSL CodePlex project to expose this functionality. I have added a couple of methods that allow you to find the parent and child of a work item, and hence create your own rollup script.

To make use of this all you need to do is create a TFS Alert that calls a SOAP end point where the Alerts DSL is installed. This end point should be called whenever a work item changes state. It will in turn run a Python script similar to the following to perform the roll-up

 1
 2
 3import sys  
 4\# Expect 2 args the event type and a value unique ID for the wi  
 5if sys.argv\[0\] == "WorkItemEvent" :   
 6    wi = GetWorkItem(int(sys.argv\[1\]))  
 7    parentwi = GetParentWorkItem(wi)  
 8    if parentwi == None:  
 9        LogInfoMessage("Work item '" + str(wi.Id) + "' has no parent")  
10    else:  
11        LogInfoMessage("Work item '" + str(wi.Id) + "' has parent '" + str(parentwi.Id) + "'")
12
13 
14
15        results = \[c for c in GetChildWorkItems(parentwi) if c.State != "Done"\]  
16        if len(results) == 0:  
17            LogInfoMessage("All child work items are 'Done'")  
18            parentwi.State = "Done"  
19            UpdateWorkItem(parentwi)  
20            msg = "Work item '" + str(parentwi.Id) + "' has been set as 'Done' as all its child work items are done"  
21            SendEmail("richard@typhoontfs","Work item '" + str(parentwi.Id) + "' has been updated", msg)  
22            LogInfoMessage(msg)  
23        else:  
24            LogInfoMessage("Not all child work items are 'Done'")  
25else:  
26    LogErrorMessage("Was not expecting to get here")  
27    LogErrorMessage(sys.argv)
28
29 

So now there is a fairly easy way to create your own rollups, based on your own rules