Query Work Items changed in recent hours

Grant Holliday’s blog

Senior Service Engineer, Microsoft Visual Studio Team Foundation Service

Query Work Items changed in recent hours

  • Comments 1

Yesterday I got another question on one of our internal mailing list and I remembered it as one that I’ve answered before on OzTFS.com. The answer comes from this MSDN forum post.

By default, the TFS Work Item Query engine operates in “date precision” mode. This means that you can only run queries like:

  • Show me all the work items changed in the last week
  • Show me all the work items changed in the last day

If you want to query on work items changed within a narrower timeframe, you’ll need to call the object model directly and turn off “date precision” mode. For example:

  • Show me all the work items that have changed since 5AM today.

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace WorkItemQueryByHour
{
    class Program
    {
        static void Main(string[] args)
        {
            TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("http://your-tfsserver:8080", new UICredentialsProvider());
            WorkItemStore wis = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

            Query query = new Query(wis, "SELECT [System.Id], [System.Title], [System.ChangedDate] FROM WorkItems WHERE [System.ChangedDate] > '2008-10-01 05:00:00'", null, false);

            ICancelableAsyncResult car = query.BeginQuery();
            WorkItemCollection items = query.EndQuery(car);

        }
    }
}

  • Shai Raiten on Power Tools 2008 - TFSUsers/TFSManager and How To: Add Custom Build Steps to TeamBuild...

Page 1 of 1 (1 items)