How to get a list of child tasks from a product's Backlog element in the TFS API?

Given the specific backlog identifier of the product, I want to programmatically get a list of tasks that are children of the PBI.

I know that no fields are specified in the task that say "Parent PBI Id". I have a version of the code that works, but it is really very slow, as I do some of my filtering inside the client.

See how I am doing now:

string wiqlQuery = string.Format( "Select ID, [Remaining Work], State " + "from WorkItems " + "where (([Work Item Type] = 'Task')" + " AND ([Iteration Path] = '{0}' )" + " AND (State <> 'Removed')" + " AND (State <> 'Done')) ", sprint, storyId); // execute the query and retrieve a collection of workitems WorkItemCollection workItems = wiStore.Query(wiqlQuery); if (workItems.Count <= 0) return null; var result = new List<TaskViewModel>(); foreach (WorkItem workItem in workItems) { var relatedLink = workItem.Links[0] as RelatedLink; if (relatedLink == null) continue; if (relatedLink.RelatedWorkItemId != storyId) continue; Field remWorkField = (from field in workItem.Fields.Cast<Field>() where field.Name == "Remaining Work" select field).FirstOrDefault(); if (remWorkField == null) continue; if (remWorkField.Value == null) continue; var task = new TaskViewModel { Id = workItem.Id, ParentPbi = relatedLink.RelatedWorkItemId, RemainingWork = (double) remWorkField.Value, State = workItem.State }; result.Add(task); } return result; 
+7
source share
1 answer

MSF Agile offers a set of queries as a standard team project. Take a look at Work Elements → Iteration 1 → Iterative Lag.

Saving this query as a WIQL file on your disk is absolutely possible. Using it as a modified wiqlQuery should free you from the big filtering you do.

EDIT (in response to the comment: “Well, I did this, but the request does not mention the relationship between parent and related (child) elements”):

I opened WIQL by default "Iteration Backlog":

 <?xml version="1.0" encoding="utf-8"?> <WorkItemQuery Version="1"> <TeamFoundationServer> http://****> <TeamProject>****</TeamProject> <Wiql>SELECT [System.Id], [System.WorkItemType], [System.Title], [System.State], [System.AssignedTo], [Microsoft.VSTS.Scheduling.RemainingWork], [Microsoft.VSTS.Scheduling.CompletedWork], [Microsoft.VSTS.Scheduling.StoryPoints], [Microsoft.VSTS.Common.StackRank], [Microsoft.VSTS.Common.Priority], [Microsoft.VSTS.Common.Activity], [System.IterationPath], [System.AreaPath] FROM WorkItemLinks WHERE (Source.[System.TeamProject] = @project and Source.[System.AreaPath] under @project and Source.[System.IterationPath] under '****\Iteration 1' and (Source.[System.WorkItemType] = 'User Story' or Source.[System.WorkItemType] = 'Task')) and [System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' and Target.[System.WorkItemType] = 'Task' ORDER BY [Microsoft.VSTS.Common.StackRank], [Microsoft.VSTS.Common.Priority] mode(Recursive)</Wiql> </WorkItemQuery> 

The part of the query that retrieves the related items should be like this

 [System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' 
+2
source

All Articles