Sam
Sam

Reputation: 731

TFS API C# query syntax

I am trying to compose a query where I can execute to retrieve the backlog items like the one in the image below.

  WorkItemCollection queryResults = workItemStore.Query(
     "Select [State], [ID], [Title], [Description] " +
     "From WorkItems " +
     "Where [Work Item Type] IN ('Task', 'Bug', 'Product Backlog Item')" +
     "AND [Iteration Path]  Under 'ProjectName'" +
     "AND [Area Path]  Under 'ProjectName'" +
     "And State IN ('New', 'Approved', 'Committed')");

However, I am getting no data. not sure how to properly construct the query.

enter image description here

Upvotes: 1

Views: 1850

Answers (3)

Sam
Sam

Reputation: 731

I ended up using this query to avoid hitting TFS twice. Then, I kept track of child items based on the WorkItemLinks that is exposed at the WorkItem that you get back from executing the wql below. Once that is done, I rearranged the entries where parents come before children to give a (treeview) style.

string query = string.Format(@" 
   SELECT 
    [System.Title],
    [System.Description],
    [System.WorkItemType], 
    [System.Id]
    FROM WorkItem
    WHERE
    ([System.WorkItemType] IN GROUP 'Microsoft.RequirementCategory'  OR   [System.WorkItemType] IN GROUP 'Microsoft.BugCategory'  OR   [System.WorkItemType] IN GROUP 'Microsoft.TaskCategory' )
    AND [System.IterationPath] UNDER '{0}'
    AND [System.State] IN ('New', 'To Do')
    AND [System.AreaPath] UNDER '{0}' 
    ORDER BY 
    [Microsoft.VSTS.Common.Priority],
    [System.Id]", teamProjectName);

Upvotes: 1

Sam
Sam

Reputation: 731

I wanted up following the article below to retrieve the query.

http://blogs.msdn.com/b/jsocha/archive/2012/02/22/retrieving-tfs-results-from-a-tree-query.aspx

Upvotes: 0

Get rid of the @project in your query. I is not replaced automatically when using the API.

You also have no space before the AND's.

Your query does not match the image! You can construct the query that you want in Team Explorer and then "Save as" to the desktop. Open in notepad and copy out the query.

Upvotes: 0

Related Questions