Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Posted in Trello

Taco Tuesday: Your favorite Trello blog takeaway

Hello friends! From the community that brought you Welcome Wednesday, Throwback Thursday and Friday Fun, welcome to Taco Tuesday, a weekly discussion about all things Trello. The best part? One Tac...

88 views 7 6
Join discussion

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