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!
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Orkun.
No, no failures, but result is 0 and should be 2.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The accepted answer here, shows a solution that works:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Jose M_,
Can you try this please
it.getIssueLinkType().getName() == "Dependency" && it.destinationObject.getResolution().getName() == "Resolved"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, @Orkun Gedik, but I am getting the error
java.lang.NullPointerException: Cannot invoke method getName() on null object
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.