Query for workitems which are resolved duplicate to another workitem which itself is resolved fixed

329 Views Asked by At

I'd like to query for all WorkItems which:

  • Resolved as a duplicate
  • Are created by a specific user
  • Resolved within a specific date
  • Pointing to another workitem resolved as fixed

This is what I've tried:

string itemsMarkedDuplicateParentFixed = "Select [Target].[ID] From WorkItemLinks Where " +
                        "[Source].[System.WorkItemType] = 'Bug' And " +
                        "[Target].[System.WorkItemType] = 'Bug' And " +
                        "[Source].[System.State]='Resolved' And " +
                        "[Source].[Microsoft.VSTS.Common.ResolvedReason]='Duplicate' And " +
                        "[Target].[System.State]='Resolved' And " +
                        "[Target].[Microsoft.VSTS.Common.ResolvedReason]='Fixed' And " +
                        "[Source].[System.CreatedBy] = 'TomSelleck' And " +
                        $"[Target].[Microsoft.VSTS.Common.ResolvedDate]>='{resolvedDateFrom}' And" +
                        $"[Target].[Microsoft.VSTS.Common.ResolvedDate]<='{resolvedDateTo}'";

IEnumerable <WorkItem> appCompatBugsMarkedFixed = await vsoService.GetWorkItems(new Wiql() {
    Query = appCompatBugsMarkedDuplicateParentFixed
});

...

public async Task<IEnumerable<WorkItem>> GetWorkItems(Wiql wiqlQuery)
{
    using (var workClient = await GetClient())
    {
        var queryResults = await workClient.QueryByWiqlAsync(wiqlQuery);
        return await workClient.GetWorkItemsAsync(queryResults.WorkItemRelations.Select(x => x.Target.Id), expand: WorkItemExpand.All);
    }
}

I'm hitting this error:

Microsoft.VisualStudio.Services.WebApi.VssServiceResponseException: 'Not Found'

enter image description here

I'm struggling to find any C# examples which achieve what I want.

1

There are 1 best solutions below

1
Shamrai Aleksander On BEST ANSWER

Did you try your query through Web or Visual Studio designer? You can create a query, test it and then export it on VS (Retrieve the WIQL of a saved query created in TFS) or Wiql Editor. The example similar to your query:

Query in the designer:

enter image description here

Query wiql:

enter image description here