0
votes

I'm using the following 3 queries in order to get a list of Task/User Story/Feature relationship in a given Sprint (Iteration)

I'm no Odata expert, but it would seem in some way I could combine the 3 queries into 1 to retrieve Task, Parent (User Story) Parent (Feature) and associated Assigned Usernames.

Is this possible or could this be done another way?

Get Task and parent User Stories

https://analytics.dev.azure.com/{org}/{projectName}/_odata/v3.0-preview/WorkItems?$select=AssignedToUserSK,WorkItemId,Title,State,WorkItemType,ParentWorkItemId,RemainingWork,CompletedWork,OriginalEstimate&$expand=Parent($select=WorkItemId,Title,State,WorkItemType,ParentWorkItemId,StoryPoints,StackRank)&$filter=Iteration/IterationPath eq '{sprint}' and WorkItemType eq 'Task'";
           

Get parent Feature of User Stories (from above)

https://analytics.dev.azure.com/{org}/{projectName}/_odata/v3.0-preview/WorkItems?$select=WorkItemId, Title, State, &$filter=WorkItemId in ({parentStoryFeatureIdsStr})

Get Work Item and Assigned User Name

https://analytics.dev.azure.com/{org}/{projectName}/_odata/v3.0-preview/WorkItems?$select=WorkItemId,&$expand=AssignedTo($select=UserName)&$filter=Iteration/IterationPath eq '{sprint}' and WorkItemType eq 'Task'"
1

1 Answers

0
votes

You can have a try using $expand on Descendants to query Feature and its decendants work items(User Story and Task). See below example:

https://analytics.dev.azure.com/{org}/{projectName}/_odata/v3.0-preview/WorkItems?$filter=WorkItemType eq 'Feature'&$expand=Descendants($filter=Iteration/IterationPath eq '{sprint}'; $select=AssignedToUserSK,WorkItemId,Title,State,WorkItemType,ParentWorkItemId,RemainingWork,CompletedWork,OriginalEstimate;$expand=AssignedTo($select=UserName))

Using $expand on Descendants will return all the children User Stories and grandchildren Tasks of the Feature work items.

If you have to use $expand on Parent to query from Tasks to Parent User Stories and then to Parent Feature. I am afraid it is impossible to combine the 3 queries into 1. For the maximum depth allowed for $expand on Parent is 1 .

However, You can combine the 3 queries into 2 like below(combine the 3rd query into the 1st query):

https://analytics.dev.azure.com/{org}/{projectName}/_odata/v3.0-preview/WorkItems?$select=AssignedToUserSK,WorkItemId,Title,State,WorkItemType,ParentWorkItemId,RemainingWork,CompletedWork,OriginalEstimate&$expand=Parent($select=WorkItemId,Title,State,WorkItemType,ParentWorkItemId,StoryPoints,StackRank),AssignedTo($select=UserName)&$filter=Iteration/IterationPath eq '{sprint}' and WorkItemType eq 'Task'"