Script Field to show amount of unresolved blocking issues per issue

Jose M.
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 26, 2018

I would like to create a Scripted Custom Field that brings as result the amount of per issue linked unresolved blocking issues.

e.g. 

Issue-1

haslinks "blocked by" and "references" and more, e.g.

- Issue-2 (blocks) resolved
- Issue-3 (referenced by) unresolved
- Issue-4 (blocks) unresolved
- Issue-5 (blocks) unresolved

The issue navigator should shown, based on the example above, that the Issue-1 has 2 blocking unresolved issues. 

Is this possible?

Thanks for the help!

3 answers

1 accepted

0 votes
Answer accepted
Jose M.
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.
December 14, 2018

In our use case a second solution was needed and it is working:

import com.atlassian.jira.component.ComponentAccessor

log.warn "Starting execution for scripted field"
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueLinks = issueLinkManager.getOutwardLinks(issue.id)

def subElements = issueLinks.findAll {
it.getIssueLinkType().getName() == "Dependency" && it.sourceObject.getStatus().getName() == "Open" || it.getIssueLinkType().getName() == "Dependency" && it.sourceObject.getStatus().getName() == "In Progress" || it.getIssueLinkType().getName() == "Dependency" && it.sourceObject.getStatus().getName() == "Resolved" || it.getIssueLinkType().getName() == "Dependency" && it.sourceObject.getStatus().getName() == "Integrated" || it.getIssueLinkType().getName() == "Dependency" && it.sourceObject.getStatus().getName() == "Reopened" || it.getIssueLinkType().getName() == "Dependency" && it.sourceObject.getStatus().getName() == "Waiting Status"
}

subElements.each{
log.warn "LINK origin: ${it.sourceObject.key} destination: ${it.destinationObject.key}"
}

return subElements.size()

Very important:
After the installation of the ScriptRunner a server restart is needed.

2 votes
Orkun Gedik
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 27, 2018

Hello @Jose M_,

 

It is possible with scripted fields. Create a scripted field and configure it with HTML template.  I wrote a script for you. Place this script and let me know if it is not working. Hope this helps. 

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

Issue currentIssue = issue
Collection< IssueLink> issueLinks = ComponentAccessor.getIssueLinkManager().getOutwardLinks(currentIssue.getId())
int counter = 0;

for (IssueLink issueLink : issueLinks){
Issue destinationIssue = issueLink.getDestinationObject()
Long issueLinkId = issueLink.getId()
if ( issueLinkId == "Blocked by issue link id here" && destinationIssue.resolution.getName() == "Unresolved"){
counter = counter + 1
}
}
String output = "<p>" + String.valueOf(counter) + "</p>"

return output

 

Best Regards.

Jose M.
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 27, 2018

Hello @Orkun Gedik,

thanks a lot for your help. Unfortunately right now I was not successful.

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

Issue currentIssue = issue
Collection< IssueLink> issueLinks = ComponentAccessor.getIssueLinkManager().getOutwardLinks(currentIssue.getId())
int counter = 0;

for (IssueLink issueLink : issueLinks){
Issue destinationIssue = issueLink.getDestinationObject()
Long issueLinkId = issueLink.getId()
if ( issueLinkId == "depends on" && destinationIssue.resolution.getName() == "Unresolved"){
counter = counter + 1
}
}
String output = "<p>" + String.valueOf(counter) + "</p>"

return output

or 

..
if ( issueLinkId == 10030 && destinationIssue.resolution.getName() == "Unresolved"){
...

does not work

Do I have to use a separate HTML Template?

Thanks again for your help!

Orkun Gedik
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 28, 2018

Hello @Jose M_,

Please be sure "issueLinkId" takes Long not String. No you can also use proper templates its depends on how you want to show the output on screen. 

What is the problem? Is there any error on code or only field does not appear on screen?

Like Jose M. likes this
Jose M.
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 29, 2018

Hi Orkun.

No, no failures, but result is 0 and should be 2.

 

0 votes
Jose M.
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 29, 2018

The accepted answer here, shows a solution that works:

https://community.atlassian.com/t5/Jira-questions/Scripted-Field-to-return-number-of-cloned-issues-not-working/qaq-p/56081

But how to extend the script below, order to skipt unresolved issues or Resolved / Closed issues? 

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueLinks = issueLinkManager.getOutwardLinks(issue.id)

def subElements = issueLinks.findAll {
it.getIssueLinkType().getName() == "Dependency"
}

return subElements.size()

 Any help would be very appreciated.

Orkun Gedik
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 29, 2018

Hello @Jose M_,

 

Can you try this please


it.getIssueLinkType().getName() == "Dependency" && it.destinationObject.getResolution().getName() == "Resolved"
Jose M.
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 30, 2018

Thanks, @Orkun Gedik, but I am getting the error

java.lang.NullPointerException: Cannot invoke method getName() on null object

 

Jose M.
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.
December 3, 2018

Hi @Orkun Gedik,

I have tried to use 

it.getIssueLinkType().getName() == "Dependency" && it.destinationObject.getStatus().getName() == "Open"

 and it works to find the issues in status Open.

I would like to find only the issue, not in status Closed or Verified.

How could it work?

Thanks a lot for any help.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events