Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access the Kanban Column (a Team-Specific Field) for a Work Item

Is there a way to programmatically access the "Kanban Column" for a WorkItem using the TFS 2012 API?

Using the Scrum 2.2 template, the history of a Bug or Product Backlog Item shows "[MyProject\MyTeam] Kanban Column" as a changed field whenever a work item is dragged between Kanban columns on the Board, but the field is not accessible when specifically retrieving a work item through the TFS API.

It also shows up as a changed field in the WorkItemChangedEvent object when implementing the ProcessEvent method on the Microsoft.TeamFoundation.Framework.Server.ISubscriber interface.

Workaround: A coworker found a blogpost about creating a read-only custom field to persist the value of the Kanban Column, taking advantage of the WorkItemChangedEvent to capture the latest value. It is then possible to query on this column. One problem with this approach is that only a single team's Kanban Column can be tracked.

Update: According to this blogpost, the Kanban Column is not a field, rather a "WIT Extension". This may help lead to an answer.

like image 384
JoeGaggler Avatar asked Aug 12 '13 17:08

JoeGaggler


2 Answers

I've found a way to read the value using the TFS 2013 API, inside the ISubscriber.ProcessEvent method:

var workItemId = 12345;
var extService = new WorkItemTypeExtensionService();
var workItemService = new WorkItemService();
var wit = workItemService.GetWorkItem(requestContext, workItemId);
foreach (var wef in extService.GetExtensions(requestContext, wit.WorkItemTypeExtensionIds))
{
    foreach (var field in wef.Fields)
    {
        if (field.LocalName == "Kanban Column" || field.LocalName == "Backlog items Column")
        {
            // Access the new column name
            var columnName = wit.LatestData[field.Field.FieldId];
        }
    }
}
like image 141
JoeGaggler Avatar answered Nov 16 '22 02:11

JoeGaggler


If you are prepared to dig into the database you can mine this information out. I don't fully understand the modelling of the teams in TFS yet but first you need to work out which field id the team of interest is storing the Kanban state in as follows (TFS 2012):


 USE Tfs_DefaultCollection
 SELECT TOP(10)
        MarkerField + 1 as FieldId,* 
 FROM tbl_WorkItemTypeExtensions with(nolock) 
 JOIN tbl_projects on tbl_WorkItemTypeExtensions.ProjectId = tbl_projects.project_id
 WHERE tbl_projects.project_name LIKE '%ProjectName%

Then replace XXXXXXXX below with the FieldId discovered above


 SELECT TOP 1000 
        wid.Id, 
        wia.State, 
        wid.StringValue as Kanban, 
        wia.[Work Item Type], 
        wia.Title, 
        tn.Name as Iteration
 FROM tbl_WorkItemData wid with(nolock)
 JOIN WorkItemsAre wia on wia.ID = wid.Id
 JOIN TreeNodes tn on wia.IterationID = tn.ID
 WHERE FieldId = XXXXXXXX and RevisedDate = '9999-01-01 00:00:00.000'
 ORDER BY Id
like image 23
Mr H Avatar answered Nov 16 '22 02:11

Mr H