Query Work Items changed in recent hours

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);

        }
    }
}

Published 01 October 08 01:45 by grantholliday

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Team System News said on October 7, 2008 9:36 AM:

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

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

Search

This Blog

Syndication

Page view tracker