Suresh Balaji
Suresh Balaji

Reputation: 109

How to query TFS Database for work item field changed on specific date

I want to query TFS work items which has been edited on a particular date. using Changed Date = @Today - 1 ,I can get workitems which was changed yesterday but If i change work item today and query for changes made for yesterday it will be ignored since its change date is today. So i want to query through history searching for work items that is changed on some x day

EDIT from Comments:

I will be more clear. I want to check whether a field (ex. System.AssignedTo field) is changed on a given day.

Upvotes: 1

Views: 4480

Answers (1)

DaveShaw
DaveShaw

Reputation: 52788

I don't think it's possible using the normal Queries or WIQL.

You can get the results using the TFS API. Here's a query that will get you the results you need. You just need to add a few references to some of the TFS Assemblies.

void Main()
{
    const String CollectionAddress = "http://mytfsserver/tfs/MyCollection";

    using (var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(CollectionAddress)))
    {
        var server = tfs.GetService<WorkItemStore>();
        var changes =
            server.Query("select * from WorkItems where [System.ChangedDate] = @Today")
            .Cast<WorkItem>()
            .SelectMany(wi =>
                wi.Revisions
                .Cast<Revision>()
                .SelectMany(r =>
                    r.Fields
                    .Cast<Field>()
                    .Where(f => !String.IsNullOrEmpty(f.OriginalValue as String) && f.Value != f.OriginalValue && f.ReferenceName == "System.AssignedTo")
                    .Select(f => new { wi.Id, f.OriginalValue, f.Value, f.ReferenceName, })))
            .Dump();
    }
}

Upvotes: 5

Related Questions