2

I have to obtain the value of a field in a single work item. The query only returns one work item, because in my where clause I specify exaclty which Work Item Id I want. It's sort of a GetFieldByWorkItemId kind of method:

public double GetOriginalEstimate(object id)
{
    WorkItemCollection queryResults = workItemStore.Query(
        " SELECT [Original Estimate]" +
        " FROM WorkItems " +
        " WHERE [ID] = " + Convert.ToInt32(id)
        );

    return 0;
}

My two questions are:

  1. How can I get a work item from the WorkItemCollection queryResults by Id
  2. How can I get the value of the field that I'm interested in: [Original Estimate]
Jean-François Beaulieu
  • 4,305
  • 22
  • 74
  • 107

1 Answers1

4

Rather than run a query, you can retrieve a single work item by it's ID:

WorkItemStore.GetWorkItem(int id)["Original Estimate"]
granth
  • 8,919
  • 1
  • 43
  • 60
  • 1
    It's funny that there is no documentation about how to get a specific field from a work item! That worked, thanks. – Jean-François Beaulieu Feb 15 '12 at 14:13
  • 1
    It's actually described in the 'Remarks' section of the WorkItem class. http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.workitemtracking.client.workitem.aspx There are also more examples in the TFS 2010 SDK: http://archive.msdn.microsoft.com/TfsSdk – granth Feb 16 '12 at 03:41