ScriptRunner Scripted Field to Show "is blocked by" Linked Issues

Kellen Schroeter August 23, 2019

Hey guys! I'm looking to create a scripted field to show only issues with the link type "is blocked by" 

Ideally, it returns a click-able subset of the 'Links' column in the Issue Search that only contains links of the type "is blocked by". 

I have a scripted field returning the superset of all issue links, but I'm not sure how to narrow it down. Any Help?

 

import com.atlassian.jira.component.ComponentAccessor
def ShowLinks = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, issue.reporter).getAllIssues()
ShowLinks

 

Thanks! 

2 answers

1 accepted

2 votes
Answer accepted
Ilya Turov
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.
August 24, 2019

As you know, issueLink has a direction it goes, so issueLinkManager has methods to extract outward and inward links (getOutwardLinks(issueId) and getInwardLinks(issueId) respectively), I guess "is blocked by" is either inward or outward name of a link type which is called like "Blocks" or something.

so code might look like this:

import com.atlassian.jira.component.ComponentAccessor

ComponentAccessor.issueLinkManager.getInwardLinks(issue.id).findAll {
it.issueLinkType.inward == "is blocked by"
}*.destinationObject

you still need to play with either getting inward or outward links, filtering links by issueLinkType inward name, outward name, regular name or id (whichever you'd find better) and returning destinationObjects or sourceObjects of filtered links.

but the basic structure of code should look like this

Kellen Schroeter August 26, 2019

Thanks so much for the help! 

M Vijay Kumar
Contributor
April 9, 2020

I have a Similar requirement, were you able to solve the issue?

0 votes
PD Sheehan
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.
August 26, 2019

You could try something like this:

import com.atlassian.jira.component.ComponentAccessor
def ShowLinks = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, issue.reporter)
ShowLinks.getInwardIssues('Blockers').collect{"""<a href="/browse/$it.key">$it.key</a> """}.join("<br>")
Kellen Schroeter August 26, 2019

Thanks for the tip on the ".collect()" I tacked that on the end of Ilya's help and it all works like a charm

 

import com.atlassian.jira.component.ComponentAccessor

def ShowLink = ComponentAccessor.issueLinkManager.getInwardLinks(issue.id).findAll {
it.issueLinkType.inward == "is blocked by"
}*.sourceObject.collect{"""<a href="/browse/$it.key">$it.key</a> """}.join("<br>")

ShowLink

Suggest an answer

Log in or Sign up to answer