adk wrote:The goal is to have a query which I can do for R1 that will show me R11, R12, R13 (which I can already do with linkedWorkItems:R1) but ALSO show me the linked Workitems of R11 and R12.
My Idea was "linkedWorkItems:R1 AND linkedworkitems:linkedWorkItems:R1) but unfurnatuly this didn't work.
I think you cannot solve everything in one
query or maybe it is possible but is just plain complicated and there is an easier way to do it without queries.
Here is my proposed solution, it just uses a query at the root level for getting R1 and R2 but the rest is done with the
getLinkedWorkItems() method:
Code: Select all
#set($projectID = "$page.space.projectId")
## This is a dummy query, replace it with your own with which you get R1 and R2
#set($rootLevelQuery = "project.id:$projectID AND type:requirement title:R1 OR title:R2")
#set($sortingParameter = "title") ## for ordering the query result
#set($rootLevelItems = $trackerService.queryWorkItems($rootLevelQuery, $sortingParameter) )
#foreach($rootItem in $rootLevelItems) ## start foreach1
<H1> - $rootItem.getId() </H1> ## Output of the Root item
#set($linkedItemsFirstLevel = $rootItem.getLinkedWorkItems() ) ## getting the linked items of the root level item
## we need to go through the first level twice, otherwise we cannot
## have a complete list of the linked items for each R1, R2 and so on at the beginning
<br /> with
#foreach($firstLevelLinkedItem in $linkedItemsFirstLevel) ## start foreach2
$firstLevelLinkedItem.getId() ,
#end ## end foreach loop2
being linked to $rootItem.getId() <br />
## now this is the loop in which we go through the linked items and get their linke ditems
#foreach($firstLevelLinkedItem in $linkedItemsFirstLevel) ## start foreach3
#set($linkedItemsSecondLevel = $firstLevelLinkedItem.getLinkedWorkItems() ) ## getting the linked items of the linked item
<br /> with
#foreach($secondLevelLinkedItem in $linkedItemsSecondLevel) ## start foreach4
$secondLevelLinkedItem.getId() ,
#end ## end foreach loop4
being linked to $firstLevelLinkedItem.getId()
#end ## end foreach loop3
#end ## end foreach loop1
Of course you need to adjust the style for youself, it is the just the bare logic that I have presented here.
Also, I may have not followed state of the art standards concerning variable naming and indents (as they look ugly when displaying the code with the code tag) but it was important to me that I present a comprehensible solution.

AND ANOTHER THING: I uploaded here at FileTea a Notepad++ version with Velcoity Syntax Highlighting available, maybe the is helpful too.
The relevant modifications for the Syntax Highlighting are not my work but I cannot find the original source anymore.
https://filetea.me/n3wzrdwOxsPTTOxVsqrai47sw