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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script Runner help needed

Edited

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

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

Thanks Joel, 

I will tinker with this and see how it goes.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

688 views 17 19
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you