Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scripted Field to return linked issues

Pete Singleton
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 3, 2021

I am attempting to script a custom field (via ScriptRunner) to return all linked, dependent issues.  It seems to work when I test it in the ScriptRunner console, but doesn't render correctly on the issue screen or search results.

Here is the script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue 
import com.atlassian.jira.issue.IssueManager 
import groovy.xml.MarkupBuilder
import com.atlassian.jira.config.properties.APKeys
 
def baseUrl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl");
def issueLinkManager = ComponentAccessor.getIssueLinkManager() 
def issueManager = ComponentAccessor.getIssueManager() 
def outwardIssueLinks = issueLinkManager.getOutwardLinks(issue.getId())
def inwardIssueLinks = issueLinkManager.getInwardLinks(issue.getId())
def subOutwardElements = outwardIssueLinks.findAll { it.issueLinkType.name == ("Dependent") }
def subInwardElements = inwardIssueLinks.findAll { it.issueLinkType.name == ("Blocks")}

def issuelist = []
assert issuelist.empty

if (subOutwardElements.size() > 0) {
  for (def i = 0; i < subOutwardElements.size(); i++ ) {
  def dependIssue = issueManager.getIssueObject(subOutwardElements[i].destinationId)
  issuelist.add(dependIssue)    
  }
}
 
if (subInwardElements.size() > 0) {
  for (def i = 0; i < subInwardElements.size(); i++ ) {
  def dependIssue = issueManager.getIssueObject(subInwardElements[i].sourceId)
  issuelist.add(dependIssue)
  }
}
 
return issuelist

 

When I select "preview" to test it on an issue is shows this:

 

Capture.PNG

However, on the issue screens it shows:

 

$issuePickerViewRenderer.getIssuePickerHtml($value)

 

2 answers

1 accepted

1 vote
Answer accepted
Pete Singleton
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 8, 2021

Thanks for confirming the script works.  I've got it working now by changing the default Searcher for the field to "Issue Key Searcher".  It defaulted to Free Text.  All working now!

Christoph Beer December 6, 2021

Thanks. This was the hint I was missing too. 

Like Antoine Berry likes this
0 votes
Antoine Berry
Community Champion
November 5, 2021

Hi @Pete Singleton ,

I just tried your script and it is working fine. Are you sure that the field is on a the view issue screen, and that the issues are linked by a "Dependent" or "Blocks" link ?

Suggest an answer

Log in or Sign up to answer