I create a query in TFS 2013 as follows:
- Choose "Work Items and Direct Links" instead of "Flat List"
- Team Project = @Project
- Remove all other clauses for source work item.
- Remove all "Filters for linked work items"
- Select radio button "Return all top level work items"
- Select radio button "Return selected link types"
- Tick 'Parent'
When I run this query in TFS, the results contain all work items that meet the source criteria, regardless of whether they have links or not.
The following WIQL is generated by the above query (if I save as File):
SELECT [System.Id], [System.Links.LinkType], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags]
FROM WorkItemLinks
WHERE ([Source].[System.TeamProject] = @project)
And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Reverse')
ORDER BY [System.Id] mode(MayContain)
However, when I run the following powershell, the resulting sourceIds only contains work items that have Parent links:
$CollectionUrl = "myCollectionUrl"
$ProjectName = "myProjectName"
'Microsoft.TeamFoundation.Client', 'Microsoft.TeamFoundation.Common', 'Microsoft.TeamFoundation.WorkItemTracking.Client' |
ForEach-Object {
Add-Type -AssemblyName "$_, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
}
[Microsoft.TeamFoundation.Client.TfsTeamProjectCollection] $tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($CollectionUrl)
[Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore]$wis = `
New-Object -TypeName Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore `
-ArgumentList ($tfs, [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStoreFlags]::BypassRules)
[string] $WIQL = "SELECT [System.Id], [System.Links.LinkType], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags]
FROM WorkItemLinks
WHERE ([Source].[System.TeamProject] = '$projectName')
And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Reverse')
ORDER BY [System.Id] mode(MayContain)"
$query = New-Object "Microsoft.TeamFoundation.WorkItemTracking.Client.Query" -ArgumentList $wis, $WIQL
$workItemLinkInfo = $query.RunLinkQuery()
$workItemLinkInfo | out-gridview
Why does the WIQL behave differently when passed through the API than when executed via the UI? Or can someone see where I'm going wrong?