Workitem Query on 2 stages

Description
adk
Posts: 1
Joined: Thu Mar 01, 2018 11:28 am

Workitem Query on 2 stages

Postby adk » Thu Mar 01, 2018 11:40 am

Hello,

I need some help with a workitem query which I want to include in a Classic Wiki Page. I created the following structure:

- R1
with R11, R12 being linked to R1
with R111, R112 being linked to R11
with R121, R122 being linked to R12
- R2
...

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.

Does anyone have an idea? As I have to do it for several Requirements a speedy solution would be much appreciated :wink:

Best Regards.

ALMighty
Posts: 80
Joined: Wed Apr 27, 2016 10:34 am
Location: Austria

Re: Workitem Query on 2 stages

Postby ALMighty » Fri Mar 02, 2018 1:51 pm

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. :wink:

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


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 8 guests