Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,300,377
Community Members
 
Community Events
165
Community Groups

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

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

1 vote
Answer accepted

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.

That is absolutely brilliant Nir. Thanks a million!

Like Nir Haimov likes this

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 Nov 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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

Improving the Create Issue Experience in Jira Service Management Cloud

Hello everyone!  We are very excited to announce some much needed changes to the issue create experience in JSM (the blue "create" button) at the top of the screen.  We have just starte...

140 views 6 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you