Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

How to create a custom field which displays the number of issues in an epic?

Hi all,

my request is about the ticket type Epic.

When stories are linked to an epic, they are listed as "Issues in epic".

I would like to display the total number of "Issues in epic" as a number in the epic.

Example: If my list "issues in epic" contains 15 items, I want to show this value as a number in a custom field "Total number of tickets".

I have created a scripted field for this with scriptrunner and would be happy if you could support me with the matching script.

To get all related issues I'm using this script below. When i use a textfield-template, it correctly gives me the linked keys. Now I need a function that sums the number of keys so I can display them with a number-field-template

Thanks,
Alexander

 

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(issue.issueType.name=="Epic") {
 return getEpicIssueKeys(issue)
}

return null

 

1 answer

1 accepted

1 vote
Answer accepted
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 16, 2022

Hi @Alexander B_ and welcome to the community,

If your result is a list or array, why you don't use the .size to get the number of issues in that list?

Hi @Alex Koxaras _Relational_ 

thank you! That helped. Find my modified script below.

Cheers!

 

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 count the number of issue keys in an Epic
def getEpicIssueKeys(Issue issue) {
 def epic = (Option)Option.option(issue)
 def epicLinkManagerImpl = getBean("epicLinkManagerImpl");
 numberOfIssuesInEpic = epicLinkManagerImpl.getIssuesInEpic(issue).size()
 return numberOfIssuesInEpic
}

if(issue.issueType.name=="Epic") {
 return getEpicIssueKeys(issue)
}

return null
Like # people like this
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 16, 2022

Nice! Good to know that!

Like Alexander B. likes this

I was looking for this solution as well. Thank you for posting this!

Like Alexander B. likes this

Suggest an answer

Log in or Sign up to answer