Scripted field - check issue status of linked issues

Paulina Wegrzyn March 9, 2016

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

0 votes
Answer accepted
JamieA
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.
March 9, 2016

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

Paulina Wegrzyn March 9, 2016

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