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

This widget could not be displayed.

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
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

206 views 1 3
Join discussion

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