Can Scriptrunner be used to show the name of a dependent issue instead of its key?

Chris Baker November 18, 2018

I am using Scriptrunner to display a list of dependencies between issues within a Dashboard for use by the members of the program team and their sponsors. While this is useful to some degree, it would be more helpful to show the name of the dependent issue instead of the Key. I.E. in the dashboard below, we want to show the name of the dependent issue rather than the Key so that we can see what it is without having to click into each one.

Dependencies.png

I haven't been able to work out how to do this however. Is it possible?

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 19, 2018

Here is a complete code that will work for you:

enableCache = {-> false}
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager

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.contains("Epic") && it.issueLinkType.name != ("Cloners") && !it.issueLinkType.name.contains("subtask")}
def subInwardElements = inwardIssueLinks.findAll { !it.issueLinkType.name.contains("Epic") && it.issueLinkType.name != ("Cloners") && !it.issueLinkType.name.contains("subtask")}
def resultYes = "<p>";

if (subOutwardElements.size() > 0) {
for (def i = 0; i < subOutwardElements.size(); i++ ) {
def dependIssue = issueManager.getIssueObject(subOutwardElements[i].destinationId).toString() + " " + issueManager.getIssueObject(subOutwardElements[i].destinationId).getSummary()
resultYes = resultYes + "<div>" + dependIssue + "</div>"
}
resultYes = resultYes + "</p>"
return resultYes
}

if (subInwardElements.size() > 0) {
for (def i = 0; i < subInwardElements.size(); i++ ) {
def dependIssue = issueManager.getIssueObject(subInwardElements[i].sourceId).toString() + " " + issueManager.getIssueObject(subInwardElements[i].sourceId).getSummary()
if (!resultYes.contains(dependIssue.toString())) {
resultYes = resultYes + "<div>" + dependIssue + "</div>"
}
}
return resultYes
}

if (subOutwardElements.size() == 0 || subInwardElements.size() == 0) {
return "No"
}

 Note that i exclude links of type "epic", "sub-task" and "cloners"

If you want to see all link types just remove the exclude from the code.

I tested it before sending to you and it works.

Chris Baker November 19, 2018

That is absolutely brilliant Nir. Thanks a million!

Like Nir Haimov likes this
0 votes
Chris Baker November 19, 2018

The filter that is shown above is:

issueFunction in linkedIssuesOf("project = VCS and status != done") ORDER BY "Epic Link

I have a custom scripted field called "Depended By". The following code I have written to get the Summary name of the  first issue instead of the summary name of the linked issue. I've no idea how to get it unfortunately. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def linkedIssues = issueLinkManager.getOutwardLinks(issue.id)
def summary

issueLinkManager.getInwardLinks(issue.id).each {issueLink ->

for(Iterator outIterator = linkedIssues.iterator(); outIterator.hasNext();){
IssueLink issueLink2 = (IssueLink) outIterator.next()
linkedIssues = issueLink2.getSourceObject().getSummary()
summary = linkedIssues

}

}
return summary

 

0 votes
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 19, 2018

Hi,

If you ask if it can be done, than yes.

 

You can create custom scripted field to show you what you want, than just add this field to your filter in Dashboard.

If you expect to get a complete code for this than i'm sorry, you will have to write it on your own.

If you have something you already started to write and you need more guidance, let me know and i will gladly help you

 

Cheers,

Nir.

TAGS
AUG Leaders

Atlassian Community Events