create hyperlinks to work item tracker view

Description
nawomb
Posts: 1
Joined: Fri Jan 27, 2017 7:13 pm

create hyperlinks to work item tracker view

Postby nawomb » Fri Jan 27, 2017 7:33 pm

Hi All,

I am currently working in a script inline widget on the MyPolarion Page to create a link to the work item tracker view for each project which the user has assigned and unresolved work items. My current code is here:

Code: Select all

#set($assignedItems = $trackerService.queryWorkItems("assignee.id:$me AND NOT HAS_VALUE:resolution"))
#set($projsList = [])
#foreach($item in $assignedItems)
  #if(!$projsList.contains($item.getProject()))
    $projsList.add($item.getProject())
  #end
#end
#foreach($proj in $projsList)
    <a href="/polarion/#/project/$proj/workitems?query=NOT HAS_VALUE:resolution AND assignee.id:$me">$proj</a>
#end


The code inside the second for loop doesn't display anything; when I moved it out of the loop it displays a link that directs me to the work item tracker view for the entire repository. Am I missing something? Why can't this code execute in a loop? Any suggestions?

Thanks

martins
Posts: 181
Joined: Thu Nov 05, 2009 3:24 pm

Re: create hyperlinks to work item tracker view

Postby martins » Fri Feb 17, 2017 12:43 pm

Hello,

the ".getProject()" method returns an object of type "ITrackerProject", therefore your "$proj" is an object and not a string.

You better use method ".getProjectId()" which returns a string, or you have to write "$proj.getId()" in your second loop.

Martin

smarty
Posts: 53
Joined: Fri Jan 18, 2013 4:43 pm
Location: Germany / Frankfurt
Contact:

Re: create hyperlinks to work item tracker view

Postby smarty » Wed Mar 01, 2017 7:18 pm

Hello nawomb,

I tried your code and used "$proj.getId()" in the second loop as MartinS suggested, but did not get the hyperlink neither.
But the root cause is $trackerService.queryWorkItems().
Unless you specify a second parameter "sort by WI field id" (cf. Polarion SDK) $assignedItems remains empty.

Here is a working code for a classic wiki page which renders the links per project:

Code: Select all

#set($userId = $me)
#set($queryWi = "assignee.id:$userId AND NOT HAS_VALUE:resolution")

## sort by WI field id (velocity query syntax, ascending: "id", descending: "~updated")
#set($assignedItems = $trackerService.queryWorkItems($queryWi,"~updated"))

1.1.1.1 Size of PObjectList \$assignedItems: $assignedItems.size()

#set($projsList = [])
#foreach($item in $assignedItems)
  ## renders return value "true" in wiki !?!
  #if(!$projsList.contains($item.getProject()))
    $projsList.add($item.getProject())
  #end
#end

1.1.1.1 $assignedItems.size() Workitems assigned to $userId in $projsList.size() project(s):
#foreach($proj in $projsList)
    * <a href="/polarion/#/project/$proj.getId()/workitems?query=$queryWi" target="_blank" title="Open Table View in new window">$proj.getName()</a>
#end

Hope this helps, although I cannot explain why the value "true" is rendered with each #if evaluation :shock:

Regards, Martin
My environment: Polarion ALM 2016 SR2 on Windows Server 2012,
Polarion-JIRA Connector to JIRA 7.x

fbachmann
Posts: 47
Joined: Thu Apr 24, 2014 12:10 pm

Re: create hyperlinks to work item tracker view

Postby fbachmann » Mon Jun 03, 2019 1:19 pm

This solution works fine - FWIW, this is the part of the code which returns "true":

Code: Select all

 $projsList.add($item.getProject())


So my suggested workaround (standing on the shoulders of forum giants :D ) is

Code: Select all

#set($userId = $me)
#set($queryWi = "assignee.id:$userId AND NOT HAS_VALUE:resolution")

## sort by WI field id (velocity query syntax, ascending: "id", descending: "~updated")
#set($assignedItems = $trackerService.queryWorkItems($queryWi,"~updated"))

1.1.1.1 Size of PObjectList \$assignedItems: $assignedItems.size()

#set($projsList = [])
#foreach($item in $assignedItems)
  #if(!$projsList.contains($item.getProject()))
       ## NB: dummy setting needed to avoid outputting "true" for every .add operation
    #set ($dummy=$projsList.add($item.getProject()))
  #end
#end

1.1.1.1 $assignedItems.size() Workitems assigned to $userId in $projsList.size() project(s):
#foreach($proj in $projsList)
    * <a href="/polarion/#/project/$proj.getId()/workitems?query=$queryWi" target="_blank" title="Open Table View in new window">$proj.getName() ({workitems: query=$queryWi| project=$proj.getId() | display=count}) </a>
#end


François

PS: if you watch closely, you'll discover that I also enhanced the original by adding the number of found work items by project...


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 4 guests