Is possible this CF+Script?

DanielG
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.
March 7, 2013

Hi,

I want to implement a Custom Field in Jira that counts how many links (in total) that depends of issue. Let me to explain better: the only that I want is that have a issue 'A' in project that have another (for example) that depends of issue 'A'. So in CF that I want to create, in this example will have value '1' because only have 1 issue that depends of this issue.

Is this possible to implement in Jira?

Thanks in advance,

Daniel

3 answers

1 accepted

4 votes
Answer accepted
DanielG
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.
March 12, 2013

I do this script with 'Script Runner' plugin and the following code (if any is interested :D ):

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Category
import com.atlassian.jira.issue.link.IssueLink;
double numberLinks = 0
linkType = ["Duplicate"]

linkMgr = ComponentManager.getInstance().getIssueLinkManager()
for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {
        if (linkType.contains(link.issueLinkType.name)) {
            	numberLinks = numberLinks + 1

    }
 
}
return numberLinks

Thomas PF March 13, 2013

Works for me, thanks!

Jozef Kotlár
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.
March 13, 2013
to make it more groovy...
import com.atlassian.jira.component.ComponentAccessor
def linkType = ["Duplicate"]

return ComponentAccessor.issueLinkManager.getInwardLinks(issue.id)).count {
        linkType.contains(it.issueLinkType.name)
}


1 vote
Henning Tietgens
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.
March 7, 2013

Hi,

you can use the Script Runner plugin and create a scripted custom field which counts the links.

Henning

Jozef Kotlár
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.
March 8, 2013

Just to note - it will show correct value on issue view screen, but for accurate value in issue navigator (and search indexes) you should develop some sort of reindexing for linked issues.

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.
March 8, 2013

Really? I think the act of linking causes both source and target to be reindexed.

0 votes
Dinesh Dhinakaran
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 18, 2013

can get the script pls

Suggest an answer

Log in or Sign up to answer