Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner scripted field: Need sum of story points only where resolution is fixed, done or empty

Dan Goldman
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 3, 2018

Greetings

We currently have a scripted field which gives a percentage of stories estimated to an epic.

This has worked well for us, however we now want to only summarize stories when the story points field is > 0, where the resolution is empty, or set to the values of "Fixed" or "Done".  All other stories, we do not wish to summarize.

Below is our current code.

Any recommendations on how to obtain the resolution value, and add the above criteria?

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor;
def componentManager = ComponentManager.getInstance()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
double totalStoriesEstimated = 0
double totalStoriesUnestimated = 0
double totalStories = 0
double percentEstimated = 0
double SP = 0
def storyestimated = false

customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10073");

if (issue.getIssueTypeId() != "17") {
    return null
}

issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->
    if (issueLink.issueLinkType.name == "Epic-Story Link" ) {
        SP = (double)(issueLink.destinationObject.getCustomFieldValue(customField) ?: 0)
        totalStories++;
        if (SP > 0) {
            totalStoriesEstimated++;
        }
    }
    
        percentEstimated = ((totalStoriesEstimated ) / totalStories) * 100;
    if (percentEstimated <= 0) {
        percentEstimated = 0}
}



return percentEstimated

 

1 answer

1 accepted

2 votes
Answer accepted
Alexey Matveev
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.
April 3, 2018
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor;
def componentManager = ComponentManager.getInstance()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
double totalStoriesEstimated = 0
double totalStoriesUnestimated = 0
double totalStories = 0
double percentEstimated = 0
double SP = 0
def storyestimated = false

customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10073");

if (issue.getIssueTypeId() != "17") {
    return null
}

issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->
    if (issueLink.issueLinkType.name == "Epic-Story Link" ) {
        SP = (double)(issueLink.destinationObject.getCustomFieldValue(customField) ?: 0)
        def resolution = issueLink.destinationObject.getResolution()
if (resolution == null || resolution.name == "Done" || resolution.name == "Fixed") {
totalStories++;
        if (SP > 0 ) {
            totalStoriesEstimated++;
        }
}  
   }
    
        percentEstimated = ((totalStoriesEstimated ) / totalStories) * 100;
    if (percentEstimated <= 0) {
        percentEstimated = 0}
}



return percentEstimated
Dan Goldman
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 3, 2018

Really appreciate your assistance @Alexey Matveev!  Will give this a try and let you know if we have any questions.

Suggest an answer

Log in or Sign up to answer