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

0 votes

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,847 views 12 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot