/** This example script field script should configured to display on the 'Issue Sidebar' and configured to run for just the *Epic* issue type only and should be set as the Number return type. * This example shows how to get all the story points for all story issues insdie the epic and to sum these up and to store these in the script field. * "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner* license shall be granted a non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed or* amended and must be included in any circumstances where the code snippet is shared by You or a third party." */// Check if the issue is an Epic issueif(issue.fields.issuetype.name=="Epic"){// Get the field idsdeffields=get('/rest/api/2/field').asObject(List).bodyasList<Map>// Get the Story Points custom field to use in the scriptdefstoryPointsField=fields.find{it.name=="Story Points"}?.id// Handle if the Story Points Field does not existif(storyPointsField==null){logger.info("Story Points field does not exist ");return;}// Get all issues below the the Epic IssuedefallStories=get("/rest/agile/1.0/epic/${issue.key}/issue")// The JQL query to return all stories, modify this if you wish to return other issue types inside of the epic as well..queryString("jql","parentEpic =${issue.key} and issuetype = 'Story'").queryString("fields","parent,$storyPointsField").asObject(Map).body.issuesasList<Map>// Sum the Story Points for all the Story issues returneddefestimate=allStories.collect{Mapstory->story.fields[storyPointsField]?:0}.sum()// return the estimate value if it is not null and return 0 if it has no valuereturnestimate?:0;}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.