Scripted field - check issue status of linked issues

Hi, 

Now I have a working scripted field which calculates story points of all issues linked with Epic-Story Link. The sum of Story Points is shown in the Epic issue type. Code below:

import com.atlassian.jira.component.ComponentAccessor;
 
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def totalSP = 0.0
enableCache = {-> false}

issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->
    if (issueLink.issueLinkType.name == "Epic-Story Link") {
        customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points")
        def SP = issueLink.destinationObject.getCustomFieldValue(customField) as Double ?: 0.0
        log.debug("SP value ${SP}")
        totalSP += SP
    }}
 
return totalSP as Double


Do you know if there is any possibility to somehow limit the calculation of story points based on issue status? (now story points are calculated from all linked with epic link issues (despite of their status), I want to have a calculation only of issues that are not in Done status).

I was trying to add additional condition like (in bold):

import com.atlassian.jira.component.ComponentAccessor;

def doneNames = ["Done"]
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def totalSP = 0.0
enableCache = {-> false}


issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->
if ((!(issue.statusObject.name in doneNames)) && issueLink.issueLinkType.name == "Epic-Story Link") {
customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points")
def SP = issueLink.destinationObject.getCustomFieldValue(customField) as Double ?: 0.0
log.debug("SP value ${SP}")
totalSP += SP
}}
return totalSP as Double

Unfortunately it does not work, could you pelase advise why?


Thanks,

Paulina

1 answer

1 accepted

I would write it like this:

import com.atlassian.jira.component.ComponentAccessor

def doneNames = ["Done"]
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def totalSP = 0.0
enableCache = {-> false}

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points")

issueLinkManager.getOutwardLinks(issue.id).findAll {
    it.issueLinkType.name == "Epic-Story Link"
}.findAll {
    it.destinationObject.status.name in doneNames
}.each {
    totalSP += it.destinationObject.getCustomFieldValue(customField) as Double ?: 0.0
}
 
return totalSP as Double

(untested).

Thank you Jamie!

It is working great.

The only change which I made is: !(it.destinationObject.status.name in doneNames) as I want all issues not in status Done.


Thanks once again!

Paulina

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,820 views 18 22
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you