Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Script Runner help needed

Vlad
Contributor
March 15, 2018

Hello,

We have a need for a script that calculates all Story Points for any project/issue/linked/sub-task under it.


So if we have an issue with lots of other issues linked to it in any way, the need is to calculate ALL the Story Points for all those tickets and any sub-task or other linked issues under there and so on...basically a top down total count.

Looking so far only gets me small snips of either getting per story or per issue type or per link. Hoping some of you can help get me a grab all values?

Thanks again in advance.

(below is what I have now that will only get items from the same issue, not to mention line 7 and 10 are throwing an error in the ScriptRunner's Scripted Field code validator)

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager ComponentAccessor.getIssueLinkManager()
def customFieldManager ComponentAccessor.getCustomFieldManager()
def StoryPoints customFieldManager.getCustomFieldObjectByName("Story Points")
def totalSP 0
totalSP += issue.getCustomFieldValue(StoryPoints)?:0
issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->
    def linkedIssue issueLink.getDestinationObject()
            totalSP += linkedIssue.getCustomFieldValue(StoryPoints)?:0
    }
return totalSP



1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Joel Janov March 31, 2018

Perhaps this may help you....this does similar but with values found on issues related to a separate project that is queried through JQL. Regardless, the outcome is a sum of all values pertaining to the Estimated Remaining Hours (getEstimate). I would assume this is similar to getting story points

 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter

def customFieldManager = ComponentAccessor.getCustomFieldManager()

// gets value of Custom Field ProjectKey
def projectKeyField = customFieldManager.getCustomFieldObjectByName("ProjectKey");
def projectKey = issue.getCustomFieldValue(projectKeyField)

//completes JQL query from Custom Field "ProjectKey"
def searchService = ComponentAccessor.getComponent(SearchService)
def jql = "project = '"+ projectKey+"'"
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issues = []

//runs query and populates array with all of the Estimated remaining hours for each issue for the custom project key
SearchService.ParseResult parseResult = searchService.parseQuery(user, jql)
if (parseResult.isValid()) {
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())

issues = searchResult.issues.collect { ComponentAccessor.issueManager.getIssueObject(it.id).getEstimate()/3600 }

}

def total

//sums all values in array
total = issues.sum()

//an array with the issues returned from the JQL
return total
Vlad
Contributor
April 2, 2018

Thanks Joel, 

I will tinker with this and see how it goes.

TAGS
AUG Leaders

Atlassian Community Events