Iterate over all issues in an Epic


I have the following code, after much searching which will return a list of issues in an Epic .

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.fugue.Option
import com.atlassian.jira.issue.Issue

//Method to get the greenhopper bean instance
def getBean(String beanId)
def ghPlugin = ComponentAccessor.getPluginAccessor().getEnabledPlugin("com.pyxis.greenhopper.jira")
def descriptor = ghPlugin.getModuleDescriptor("greenhopper-launcher")
def applicationContext = descriptor.getModule().greenHopperCacheManager.applicationContext
def beanInstance = applicationContext.getBean(beanId)
return beanInstance;

//method to return list of issue keys in an Epic
def getEpicIssueKeys(Issue issue) {
def epic = (Option)Option.option(issue)
def epicLinkManagerImpl = getBean("epicLinkManagerImpl");
issuesInEpic = epicLinkManagerImpl.getIssuesInEpic(issue)
return issuesInEpic

if("Epic") {
return getEpicIssueKeys(issue)

return null

For an Epic issue, will deliver something like:

[PR-1173, PR-1174, PR-1175, PR-1191, PR-1190, PR-1193, PR-1192, PR-1195, 
PR-1194, PR-1197, PR-1196, PR-1177, PR-1199, PR-1176, PR-1198, PR-1179,
PR-1178, PR-1180, PR-1182, PR-1181, PR-1184, PR-1183, PR-1186, PR-1185,
PR-1188, PR-1187, PR-1201, PR-1189, PR-1200, INF-89, INF-90, PR-1227,
PR-1523, PR-1524]

Now I need to to be able to iterate over that list, retrieve the issue associated with the key and sum the value of a custom field, say 'issueValue' which is double type.  That's where I got lost.

Can anyone suggest/demonstrate how to do this?

3 answers

1 accepted

1 vote
Accepted answer

Hi Ashley,

I have another solution that seems to work. I created a scripted field named EpicSum. It looks to see if the issue is of type Epic. If it is, find all issues in that epic. Once it has those issues, it looks at the custom number field "NumField" and sums up the total value between all issues in the Epic.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
enableCache = {-> false}
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

if ( == "Epic") {
// The search query
def query = jqlQueryParser.parseQuery("\"Epic Link\" in (${issue.key})")

def results =, user, PagerFilter.getUnlimitedFilter())

Double sum = 0;

results.getIssues().each {documentIssue ->;
def issue = issueManager.getIssueObject(
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("NumField")
def cfValue = issue.getCustomFieldValue(customField)?:0 as Double
sum += cfValue
return sum


Screen Shot 2017-08-09 at 10.09.44 AM.png

0 votes
Aleksandr Zuevich Community Champion Aug 09, 2017

Hi Ashley!

Now get CustomField object using CustomFieldManager and your custom field id (or type if you have only one field of this type, organize a loop, get issues using IssueManager and for each issue get the value using customFieldObject.getValue(issue).

Hi Aleksandr

That's sort of where I got to, but can't figure out the incantation to get at the IssueManager and retrieve issues etc.  Can you provide an example please?

Aleksandr Zuevich Community Champion Aug 09, 2017

ComponentAccessor.getIssueManager() to obtain the issue manager and issueManager.getIssueObject(yourIssueKey) to obtain the issue.

Hey Joshua

That looks almost just exactly what I want to do - I'll give it a try in the morning - many thanks

Hi Joshua


That nearly works.  I get

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '0.00.0' with class 'java.lang.String' to class 'java.lang.Double'.  Helpfully no line number is given.

The custom field I am querying is itself a scripted custom field with a 'Number' template, returning a Double. Not sure if that is causing the problem.

if it helps others, the follwoing incantation worked to solve the casting issue

def cfRaw = issue.getCustomFieldValue(customField)?:0
Double cfValue = Double.valueOf(cfRaw)
sum += cfValue

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,098 views 4 9
Read article

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