Script Runner get and calculate Values from Issues linked to Epic

Hi, I have Epics and "normal" issues with custom fields that hold some numbers,

I want to add another custom field to the epic that shows a calculated value based on values from the epic and its linked issues. 

I do know how to do the calculation, but I can't figure out how to get the list of linked (through epic link!) issues.

All I found was either using the normal issuelinks function or some old greenhopper code.

Any help with that?

In short, I need

-Get all tasks with epic-link = currentTask
-Get customFieldValue1 from these tasks
-Calculate against customFieldValue1 from currentTask
-Store result to customField2 in currentTask

1 answer

0 vote
Tarun Sapra Community Champion Jun 26, 2017

You can use searchService class - https://developer.atlassian.com/static/javadoc/jira/latest/reference/com/atlassian/jira/bc/issue/search/SearchService.html 

You can supply a JQL query as a parameter for the method  - parseQuery(ApplicationUser searcher, String query)

Once you get the parseResult Object, you cna get the query() and invoke the method-

search(ApplicationUser searcher, Query query, PagerFilter pager)

This will return the issues which satisfy the original jql search query - "Epic Link" = "XYZ-123" thus you will now have list of issues with the epic link as the epic key and the epic itself.

Tarun Sapra Community Champion Jun 26, 2017

And once you have all the issue objects then you can easily fetch the values of the  fields and do the calculation whcih you want.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

161 views 1 10
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