Script runner - Count of link types

c November 24, 2014

Hi,

I am trying to create a custom field to show the count of a specific type of linked items.

Outward Description - PO & Inward Description - Purchases


I am returning 0 however there are 3 link of that type.

 

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.getIssueLinkManager() 
def issueLinks = issueLinkManager.getInwardLinks(issue.getId())

def subElements = issueLinks.findAll {    issueLinks*.issueLinkType.name.contains('Purchases') }

return subElements.size() as Double

Any suggestions?

1 answer

1 accepted

1 vote
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 24, 2014

Use the actual link name, not the outward or inward description. You won't get both types because you are only looking at inward links. Then do again for outward links with the outward link name.

Example

Link name: Cloners (use this)
Outward: is cloned to
Inward: is cloned from 

c November 24, 2014

Thank you for your quick response.

I want to count the amount of Purchases the PO has. If I change it to the below I get 4, 1 cloner, 3 Purchases.

 

import com.atlassian.jira.component.ComponentAccessor
 
def issueLinkManager = ComponentAccessor.getIssueLinkManager() 
def issueLinks = issueLinkManager.getInwardLinks(issue.getId())
 
def subElements = issueLinks.findAll {    issueLinks*.issueLinkType.name.contains('Requisition') }
 
return subElements.size() as Double

 

 

c November 25, 2014

Ok it is now showing the correct number but if i add in another 'Inward' link it adds them all together. It seems to be ignoring the name.contains().

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2014

You want: issueLinks.findAll { it.issueLinkType.name.contains('Requisition') }

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2014

Actually it should be: issueLinks.findAll { it.issueLinkType.name == 'Requisition' }

Peter Newton June 22, 2020

Hi @JamieA 

I was searching for help here related to identify a "Cloners" link in a post function and nothing seems to work. I have seen multiple replies from you related to links in jira topics.

May I kindly ask you to take a look at this post, please? It should be simple but something I'm doing wrong

https://community.atlassian.com/t5/Jira-questions/Identify-a-cloned-issue-using-a-workflow-post-function-on-create/qaq-p/1408929#U1412430 

 

Thank you

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events